Creating and Accessing a Cloud-hosted Linux Virtual Machine

Khubab Ahmed
6 min readFeb 19


Using this walkthrough, you will learn how to:

  1. Register and create a VM instance using GCP (Google Cloud Platform).
  2. Configure SSH keys for secure access to the VM
  3. Access the VM using SSH
  4. Add custom firewall rules in the subnet’s security list
  5. Install RDP on the VM and access it using RDP from your PC
  6. 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:

  1. Google provide you “Compute Engine” where you easily go on created VM instance.
  2. Option for region and zone, you can select what you want but remember different region have different prices.
  3. 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.
  4. Also allow firewall rules (HTTP, HTTPS) and then create it.
Creating VM instance
VM instance created

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.

  1. You have to go to your VM instance and edit them.
  2. In your VM instance, there is advanced option where there is security option.
  3. In Security option, you have to set your public key by manually generated SSH key option.
(VM Instances->Edit-> Security and Acess-> SSH)
Add public key

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.

Write command:

ssh -i privatekey username@ip

After enter the command, you are in your machine.

  1. This is your private key which you generated on SSH configuration. You use your private key filename.
  2. Username that you use on SSH configuration.
  3. IP is your external IP which is show on your VM instance.
Access VM by using SSH

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:

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:

  1. If “Set up Firewall” is show below on your VM instance, otherwise you have to go on VPC network and Select Firewall.
  2. On the right top corner, create rule.
  3. 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:

  1. 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.[1][2][3][4] 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.


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:

sudo -s

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.

  1. 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.

That’s it:

For upcoming stories, you should follow my profile Khubab Ahmed

That’s it! Have fun & keep learning!



Khubab Ahmed

FAST-NUCES Cyber Security student '21 Batch