Add SSH Key Pair to Google Compute Engine VM Instance

Generate SSH key pair on Windows PC and add to Google Compute Engine as Project Wide SSH Key Pair

Google Cloud Platform provides few methods to authenticate to a VM instances on their platform. One of them is by using SSH keys. GCP doesn’t have a way to generate SSH key pairs automatically. So users have to generate key pairs somewhere else. You’ll learn how to generate and add SSH key pair to Google Compute Engine VM instance in this post.

SSH keys can be added to GCE per project basis and per VM instance basis. I’m looking into adding a project wide SSH key pair in this post. Project wide SSH key can be used for all VM instances in a project. Let’s get right into it.

Generate SSH Key Pair on a Windows PC

We will achieve this by using a software called PuttyGen. PuttyGen is part of Putty utilities. It includes few utilities we’ll need in the future. So go ahead and download MSI (‘Windows Installer’) and install it on your PC. Launch PuttyGen from your start menu. You’ll see a screen like below.
PuttyGen Generate SSH Key

Make sure Type of key to generate is set to RSA and click Generate. You’ll get a unique key pair within few seconds.
generated-key-pair

There are few things you can adjust after the key pair is generated. An important one is Key comment. It’ll be rsa-key- followed by date. This will be your username when you add this SSH key pair to VM instance. You probably need something easy to remember. I’ve changed it to vpsfix in above example. You should change it too.

Next up is Key passphrase. It adds an extra layer of security to your private key. This is a password you set for your private key. Passphrase you set here will be asked during the authentication. Passphrase makes sure no one can login to your VM even if they got hold of your private key file. Setting a passphrase is optional but recommended. Click Save private key and save it on a secure location. Don’t lose it. You’ll be locked out of your VM if you lose this file.

Keep the PuttyGen window open for now. We’ll need public key in the next step. You may save the public key too. But private key is all you need after this setup is complete.

Add SSH Key Pair to Google Compute Engine

We will now add generated public key file to GCE. Login to your console and navigate to Compute Engine > Metadata. Switch to SSH keys tab. You’ll see an option to add your SSH key. Copy and paste public key from PuttyGen to the text field. Finally save the public key.

That’s it. You can now use your private key to login to any VM instance you create under this project. If at some point you wish to use a different SSH key pair for an individual VM instance, you can disable this project wide key pair and add a new key pair from the VM instance settings. I hope this helps your to add SSH key pair to Google Compute Engine.

Tags
Show More

Tharindu

Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me, contact me here.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close