SSH allows you to securely connect to a remote server and execute commands on it. In this blog post, I will show you how to use the Google Cloud Console and the gcloud command-line tool to remote SSH to your Google Cloud VM instance. In this tutorial, I will describe simple way through how to create a virtual machine in Google Cloud. We can connect to it with SSH Native and Putty from our computer.
Note: I assume that the Google Cloud Console has a properly deployed VM and has public IP access and SSH Default Port 22 open and allow.
Connect SSH VM Instance wih Putty
For windows user, I am very recommended PuTTY. Putty is open-source and easy to use SSH client.
Here is step by step remote VM GCP using putty.
- Download PuTTY and install from here.
- Open PuTTY Key Generator and click Generate.
It will generate a random key. PLEASE MOVE our cursor over the blank area.

After it is done, you will get something like this.

- Change “key moment” field to something easy to type.This will become a user name later.
- Click “Save private key” in safe place folder. We need import or load this private key when connect with putty.
- Paste the Public Key to Instance VM GCP. Edit VM and jumpt to SSH Section. Add Item.

Dont forget to Save. We can see the result like this.

- Test login with putty. In the meantime go to SSH ->Auth and browse for the private key file that you saved.

- Type Public IP and “Open”. Or we can click “Save” for next login.


Connect VM Instance GCP Via SSH Linux/Mac
Mac and Linux host came with SSH connection natively. We just need to generate an SSH key pair (public key/private key) to connect securely to the virtual machine.
The private key is equivalent to a password. In our host linux or mac, generate ssh-keygen
. Next, choose a password for your login to the virtual machine or hit ENTER if you wish not to use a password. The private key (i.e. identification) and the public key will be generated as shown below.
habibza@LNV-MHZ:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/habibza/.ssh/id_rsa):
Created directory '/home/habibza/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/habibza/.ssh/id_rsa
Your public key has been saved in /home/habibza/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:f8zj9U7exPdql3E3sUiiF/LoaleqseHTqVCqh91trww habibza@LNV-MHZ
The key's randomart image is:
+---[RSA 3072]----+
| |
| |
| |
| . o . . |
| .S = + . o|
| o + * . =o|
| oo.E+ * = . @|
| ..oo+*O o o.*=|
| .. .*Boo....+*|
+----[SHA256]-----+
Next, view the key and paste the keygen to Instance VM.
habibza@LNV-MHZ:~$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDMfOtNavDuHB2uGmR1PcOpB3Yab0iCw2r8jELxdWU7/JmRPksq++UypJJUYj1bLNv++kWmCt+a2SyZ5/TNDllRGw9criisqGts3+1XeZszjEXnsfrv/c60Rmp0xNnJIp8oldQ2Y2ythO7BLdJpZaIj5yAJkvvsTkp6z/BOoomAzB+XdlVh9giEVGDZvpFHT1Lng4Rf12dQ+VRIYWo8289i6ruOu4rLD3gqYjE+MWhK3YHsImS7H3eXDkLy/xfjtS3dtK5HThEP4YGjCAmsbyAQrk+g36ofoAeilS+tUcN/IIZP2BuFyEHg1ReYES4r/xaW4W4OiZkWaZFpZTTSSIZr8InNblE3ytaku6daNqQ3uQK2yAvkYBQwu/hydS9UqqTCFjxPNpthpGcGxhJoi8nGGfaDYPU40LIktD/fC308+/qE6g7Q5D3olzGCGj3PfSWJbM2ldrvxG04092Zo3aHod5+PKAqw06MnKfRbYSCY17Jhi2YtO2z0d3LoazlNE= habibza@LNV-MHZ
Paste to Instance VM.

The last, test connect remote to Public IP VM instance via ssh in terminal.
habibza@LNV-MHZ:~$ ssh [email protected]

Until this step we can login to our vm.
Conclusion
- Save the private and public key in safe place.
- This method is just want remote SSH to instance VM. Not the GCP Environtment (project).
- For security reason, set firewall in VM Network just allow from your IP Public PC can access your VM.
Maybe usefull. Please feel free to comment.