Using this walkthrough, you will learn how to:
- Register and create a VM instance using GCP (Google Cloud Platform).
- Configure SSH keys for secure access to the VM
- Access the VM using SSH
- Add custom firewall rules in the subnet’s security list
- Install RDP on the VM and access it using RDP from your PC
- Host files using a simple HTTP server and access them using the public IP
Register and Create a VM instance
You can easily register on Google cloud platform. It provides you $300 credit free for 90 days, and you can easily register on their platform.
For creating a VM instances, there are a lot of options for you. GCP provides you a lot of computing power, memory, and so many things. You have to follow these steps:
- Google provide you “Compute Engine” where you easily go on created VM instance.
- Option for region and zone, you can select what you want but remember different region have different prices.
- For Machine configuration and boot disk, you can select anyone. It's totally on you that what is your use? What work you have to do on machine? If it for practice or you want to experience it, then you go by default, otherwise it's also on you.
- Also allow firewall rules (HTTP, HTTPS) and then create it.
Configure SSH keys for secure access to the VM
For configure the SSH keys, I use simply CMD. For creating SSH, you have to open CMD and write command:
ssh-keygen -t rsa -C username
This command create a public and private key in your user folder, but remember don't forget your paraphrase key.
You have to set your public key in your created VM instance.
- You have to go to your VM instance and edit them.
- In your VM instance, there is advanced option where there is security option.
- In Security option, you have to set your public key by manually generated SSH key option.
(VM Instances->Edit-> Security and Acess-> SSH)
Access the VM using SSH
After configuration the SSH to VM instance, now access the machine by using SSH. To access the machine, we use our CMD.
ssh -i privatekey username@ip
After enter the command, you are in your machine.
- This is your private key which you generated on SSH configuration. You use your private key filename.
- Username that you use on SSH configuration.
- IP is your external IP which is show on your VM instance.
Add custom firewall rules in the subnet’s security list
In your VM instance, you add your own firewall rule. There is also some by default rule of your VM instance which are HTTP, HTTPS, RDP, ICMP, and two more. The direction of these rules are ingress.
You can read ingress and egress documentation of Google:
Ingress and egress rules | VPC Service Controls | Google Cloud
This page explains ingress and egress rules for VPC Service Controls. VPC Service Controls uses ingress and egress…
These firewall helps you to add and block any traffic from any port. For adding and delete any rule, You have to follow these steps:
- If “Set up Firewall” is show below on your VM instance, otherwise you have to go on VPC network and Select Firewall.
- On the right top corner, create rule.
- In this rule, you select your direction, ipv4 ranges that you want and select your port.
After end of all it depends on you and your work.
Install RDP on the VM and access it using RDP from your PC
RDP provide you GUI interface of your machine. To get GUI interface of your machine, you have followed these steps:
- First you have to enter in your machine by using CMD and install RDP on your GCP machine. You have to execute this command:
sudo apt install xrdp
What is XRDP used for?
xrdp is a free and open-source implementation of Microsoft RDP (Remote Desktop Protocol) server that enables operating systems other than Microsoft Windows (such as Linux and BSD-style operating systems) to provide a fully functional RDP-compatible remote desktop experience. It works by bridging graphics from the X Window System to the client and relaying controls from the client back to X Window Server.
According to the developers, the protocol works with rdesktop, FreeRDP and Microsoft’s own Remote Desktop Client.
Xrdp - Wikipedia
From Wikipedia, the free encyclopedia xrdp is a free and open-source implementation of Microsoft RDP (Remote Desktop…
2. After completing the installation of XRDP, you have to install XFCE. You have to execute this command:
sudo apt install xfce4
XFCE4 is the latest version. It is for creating a desktop environment for your machine.
3. After this, you have to restart your XRDP. The following command you have to execute:
sudo service xrdp restart
4. Remember that you have to set password before accessing the machine. You have to enter in your root to set password by follow this command:
By this command, you have root privileges. Now you have to set password by this command:
5. After Set the password, now you have to open “Remote Desktop Connection” by simple search it. It is by default in windows.
6. You have to enter your external IP of your VM instance, and you have interacted with the machine by GUI interface.
Host files using a simple HTTP server and access them using the public IP
For host your any files and folders on HTTP server, which allows you to access by any browser; simply use your external IP.
- You have to simply install apache2 on your machine. You have to open your terminal and write simply command:
apt-get install apache2
2. After installing apache2, you have to start apache2 on your machine:
sudo service apache2 start
This command start your HTTP server, and you can access by using your external/public IP.
The Page shows on browser is by default, you can edit or change it simply on your requirement. You have to go on these folders:
In this tutorial, you learn how to set up GCP machine with safely by using SSH and have to learn how to interact with your machine by GUI interface. Also learn about HTTP server which is helpful for sharing materials.
For upcoming stories, you should follow my profile Khubab Ahmed
That’s it! Have fun & keep learning!