How to Connect with Google Cloud or AWS Instance with SSH Key

Google Cloud and AWS [Amazon Web Services] are one of the most popular and widely used cloud computing platforms in the world. They are well known for the flexibility and scalability of hardware resources. By default Google cloud or AWS instances come with SSH key authentication method rather. So users are required to add an SSH key to their instance, that can be used to login to it.

What is SSH Key? An SSH key is an access credential in the SSH protocol. Its function is similar to that of user names and passwords, but the keys are primarily used for automated processes and for implementing single sign-on by system administrators and power users.

Compared to the root password login method, using the SSH key pair is more secure. To be honest, it can be a bit complicated but offers more security while connecting to an SFTP server, because your private key remains on the client-side and they don’t get transmitted to the remote system, unlike passwords. That’s the reason why Google Cloud or AWS enables this method. In this article, we’ll discuss how to generate an SSH key pair, and use it to connect to your instance.

In the case of AWS, you get an option to download the default key pair or add one while creating the instance. But in Google Cloud, you’ve to add a key pair manually to your Virtual Machine. For this tutorial, I’m going to use Google Cloud VM instance. First, we’ll generate an SSH key and assign it to our VM.

Required Softwares:

Download and install both of these Softwares to your computer. Now, let’s proceed.

Generate an SSH Key with Puttygen

  • After running Puttygen for the first time, from your screen click on “Generate”. Don’t touch any other options if you are not required to do so. It’ll generate the SSH Key in a few moments. You need to generate some randomness by moving your mouse cursor in the blank area meanwhile to get it done.

  • You’ll get three things – Your SSH Key, Key Fingerprint and Key comment. Feel free to change the “Key Comment” with something you’re convenient with. Like your name or “root”, etc.

  • Now copy your public key first and save it somewhere else or you may export it too, then click on “save private key” and give it a name to save and export. Now, we’ve successfully generated our SSH key, the next part is to assign it with our Google cloud or AWS instance.

Adding SSH Key to Google Cloud / AWS Instance

  • Click on your instance name and go to “Edit” from the top of your screen.
  • Scroll down and you’ll get an option like this saying “You have 0 SSH Keys”. Click on Edit to add a new key.

  • Now in the public key box, paste your public SSH key which you’ve copied before. And paste it, you should see the key comment or the name of the user beside it.

  • That’s all, now save it, and you can connect to your VM instance using Putty.
  • Similarly, you can add a new SSH key to AWS Lightsail or EC2 instance by editing it or just go with the default key pair which you get during VM creation.

How to Access Google Cloud / AWS Instance using SSH Key

Now, we’ve got the public key assigned to our instance, and saved the private key in our device. That’s cool man! now let’s try to connect with the bad boy.

  • Open up Putty, in the hostname type the external IPv4 of your Google Cloud or AWS Virtual Machine instance.

  • From the menu present in the left panel of Putty, navigate to Connection> SSH> Auth and from here you will need to browse the saved private key and open it.

  • Now go back to session, and click on Open. You would get a warning like “the server’s host key is not cached in this registry….”. Hit the yes button.

  • It’ll ask you to enter the user name you wish to log in, type root to log in as the root user or your selected user name. You’re done, now you can manage your instance easily.

[Note: In Debian or some other OS, the public key generated by puttygen cannot be used directly, you’re advised to follow their formatting instructions to avoid no supported authentication methods available errors. Here I’ve used Ubuntu 18.04 LTS version, and it’s working properly]

Isn’t that great? we’ve created an SSH key and added it to our AWS or Google Cloud instance. Also, we’ve learned, how to connect with VPS instance using SSH key with Putty. So what you want to do next? let’s create a WordPress website with LEMP Stack [Ngninx, MySQL, PHP].

You can follow this detailed linked tutorial to know “how to install WordPress with LEMP stack on Ubuntu 18.04 LTS version”.

Leave a Comment

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

Scroll to Top