DevOps | Cloud | Analytics | Open Source | Programming





How To Connect Google Cloud GCP using Putty ?



This post explains How To Connect Google Cloud GCP using Putty . Our objective is to connect to our Google Cloud GCP cluster from local desktop or laptop. We will see step by step how to do that.

Prerequisites


  Now Lets follow step-by-step the process to connect Google Cloud GCP using Putty.  

Step 1 - Create SSH Keys


  • Login to GCP Console. And SSH to the VM instance.
  • Create SSH key for a new or guest user . We are creating SSH key for guest1.


testuser@cluster-bdbe-m:~$ ssh-keygen -t rsa -f ~/.ssh/guest1-gcp-ssh-key -C guest1

Generating public/private rsa key pair.

Enter passphrase (empty for no passphrase): Enter same passphrase again: 

Your identification has been saved in /home/testuser/.ssh/guest1-gcp-ssh-key.

Your public key has been saved in /home/testuser/.ssh/guest1-gcp-ssh-key.pub.

The key fingerprint is:SHA256:v5V9VGN1aIzlA74LC+9IbA1MJLMtrCqw+x4fXD/9Ey4 guest1The key's randomart image is:+---\[RSA 2048\]----+| o . .+..o|| . \* ..o+ o|| + o ..oo.|| . + ...o||. . . S . . .||.. o . o B o.+ . ||o o o \* \*.+.. .|| o o . o +E+o . ||.oo . . o... |+----\[SHA256\]-----+

testuser@cluster-bdbe-m:~$


  • You can locate the key files now . The first file is Private key & the .pub file is the Public key.


testuser@cluster-bdbe-m:~$ pwd
/home/testuser
testuser@cluster-bdbe-m:~$ 
testuser@cluster-bdbe-m:~$ ls -l .ssh/
total 8
-rw------- 1 testuser testuser 1675 Oct 17 16:17 guest1-gcp-ssh-key
-rw-r--r-- 1 testuser testuser  388 Oct 17 16:17 guest1-gcp-ssh-key.pub
testuser@cluster-bdbe-m:~$


Step 2 - Copy the Public Key Contents to the VM Instance


  • Copy the Public key contents (green colored)


testuser@cluster-bdbe-m:~$ cat .ssh/guest1-gcp-ssh-key.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSPWUojm1xbvceWjSL3bZAX6tgu
9pM0lTPwxODOJ56+2L75NOLwgIKZh8MQZ5cUyLli5/5a1NIzA2xsqZ3NSwS6iTaRnH
r2OKebC6bZ/BAhjl/hl3Kqw8CgQSJSULlnJnTEq6JbdLTc1mVNRF1SusvBpYoObs695
SzcFwMjL8mSeVUDXB3j7CVJ0+gM8wON+pW+s6x3Is14EPeUEtW0C0tSlmPgFC4d812AadiC
jOdQ6cU5J2i7yRYRQiQR5w55reU+pFwEmoHZsTewJY85327/s4vSbEscEbztoo5YpAR44/Wj2KlLA8
V/O6lAuCqbe2rGDX+r25e+/v6TWkjgPx3 guest1

testuser@cluster-bdbe-m:~$


  • Go to GCP Dashboard --> VM Instances --> Choose and click on the VM where you had SSHed in Step1.
  • Above step will take you to the below screen. Click on the Edit .
   

  • Go the SSH Key section and Paste the COPIED contents of the Public Key. And Click Save at the bottom.
 

  • So basically we linked the Public Key with the VM instance in this Step.
 

Step 3 - Download the Private Key


  • Next we download the Private key file .
  • This downloaded file will be used to connect through Putty.
  • Follow the screenshot to download the Private key file to your local Laptop or Desktop.
   

Step 4 - Convert the GCP Key to Putty's PPK Format


  • The raw ssh key file downoaded from GCP doesn't directly work with Putty. We need to convert it to Putty's PPK format.
  • We will use Puttygen which comes as part of installing Putty.
  • Load the downloaded file.
  • Then save it as private key( ppk format).
 

Step 5 - Use the PPK file to connect GCP


  • Launch Putty
  • Use the External IP of the VM . See below -
 

  • Next Click Auth and Browse and locate the putty private key or ppk file created in Step 4 .  Once you select the ppk file, click OPEN in the window shown below.
 

  • It opens the GCP Terminal . For us , as we see below it shows the username as guest1 (since we created the key for a user named GUEST1). Now you can carry on with your tasks on the Terminal.
 

Hope you find this post helpful.  

Additional Read from my Blog -