Login to GCP VM Instance with a SSH Key File

Configure Putty SSH client to login to GCP VM instance with a SSH Key File and configure auto-logins for faster and safer authentication

Google Compute Engine have tight security features in place for VM instances. They do not let outside connections to VM instances unless you configure them. This is why we had to generate and add our own SSH key pair to GCP console. We’re now going to login to GCP VM instance with a SSH key file we created in earlier tutorial.

Login in to a GCP VM instance with a SSH key file is actually an easy task. We’re going to use software called Putty. This should be already installed on your PC, if you followed my tutorial to generate SSH key pair. The MSI installer you downloaded should have installed it. If you don’t have it installed for whatever reason, you can install it from Putty utilities.

Configure Putty to use SSH Key file

Launch Putty and navigate to Connection > SSH > Auth from the category tree.
putty ssh authentication

Click Browse and select the private key file from your computer. I instructed you to save the private key file on a secure location. Now it’s time to use it.

Configure auto login to VM Instance with Putty

We’ll also configure auto-login with Putty. Without auto-login setup, you’ll have to type the username each time you want login to your VM instance. Let’s bypass that. Navigate to Connection > Data.
Auto-login with Putty

Type your VM instance username as Auto-login username. This was also created when generating SSH key pair. I set it to vpsfix, remember?

Login to GCP VM Instance with a SSH Key File

You’re now getting closer to login to your VM instance. You’ll need the IP address of your VM instance. The external IP address to be exact. You can get it from your GCP VM instances dashboard. Once you have it with you, go to Session from Putty category tree.
Putty session hostname

Type your VM instance IP address under Hostname and make sure port is set to 22 and SSH is selected as connection type. Now give your session a name under Saved Sessions and then click Save. Your session will now appear in the box below. Simply double-click it to login to your VM instance.

Login to VM Instance root Account

After you login to GCP VM instance with a SSH key file, you should change to root user account. Although your current user have sudo permissions, my tutorials always assume you’re executing command as the root user. Unless stated otherwise. Following command will log you into root account of your VM instance.

sudo -i

You can optionally enable password logins on your VM instance if you want to use passwords instead of SSH key. You can now go ahead and install Virtualmin on your GCP VM instance.

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