GCP or Google Cloud Console has gained a very decent ranking among the cloud fans because of its popularity, security and flexibility, moreover it is owned and operated by Google. Google Cloud Platform provides few methods to authenticate to a VM instance 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. Windows users can create key pairs using a tool called Putty and Puttygen which helps to SSH into the website. You’ll learn how to generate and add SSH key pair to Google Cloud Compute Engine VM instance in this post.
Also read: Set Up Apache Virtual Hosts
Add SSH Key Pair to Google Cloud in Windows
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. Learn How to Add SSH Key Pair to Google Cloud
Step 1: Generate Key Pair
We can achieve generating a key pair in windows using a tool called Puttygen. Puttygen is a part of Putty utilities, we will come to them later. First, we need to install Puttygen and generate a key pair using it, download puttygen here.
Make sure Type of key to generate is set to RSA and click Generate. You’ll get a unique key pair within few seconds.
Next, you should provide a key comment under Key comment label. It’ll be RSA-key-followed by date by default. Key comment 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 techbiriyani in above example. You should change it too.
Next up is Key passphrase. It adds an extra layer of security to your private key and also helps in simplify login process. 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 log in 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, ypu may save it as public key too by clicking Save public key button. Don’t lose this keys. You’ll be locked out of your VM if you lose this file. We’ll need the public key in the next step. But the private key is all you need after this setup is complete.
Keep the PuttyGen window open for now. Click on Load button
Select the Key Pair you saved in the previous step.
Now enter the key passphrase given while generating the key pair
Now select all keys generated under the label Key, copy it and we need to paste the same in your instance on Google Cloud Console.
Step 2: Add key pair to your Instance
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. Edit this field then 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. Hope you have successfully integrated your SSH key pair to Google Compute Engine.
If you’d like to encrypt your website contents, you can look at this article on How To Secure Apache with Lets Encrypt on Ubuntu 18.04.