Sudipta Deb

Sudipta Deb

Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect

In this blog post, I am going to show you step by step way to connect to your Google Cloud Virtual Machine Instances using SSH and MacOS Terminal.

Watch The Video Or Read The Article (or do Both)

Quick Explanation Of How It Works

For this one to work, we need to create two keys – Public and Private Key. After creating the keys, we need to upload the public key to Google Cloud. And then using the Private Key, we will be able to connect with Virtual Machine instances from MacOS Terminal.

Step 1 – Generate Public and Private Key

In order to generate Public and Private Key, open your MacOS Terminal and then execute the below command.

ssh-keygen -t rsa -f <LOCATION_TO_STORE_THE_KEY> -C sudipta

 

This will generate two keys (Public and Private) in the folder that was mentioned.

Step 2 – Upload Public Key In Google Cloud

To do this, we need to open the Google Cloud Console first and then go to Compute Engine -> Settings -> Metadata. Go to SSH KEYS and add the Public Key here.

In order to add the public key, first open the public key (with extension .pub) we have generated in the previous step in text editor. Then copy the content and paste it inside Google Cloud’s Compute Engine -> Settings -> Metadata -> SSH KEYS section.

Once you add the public key, it will look like –

Step 3 – Connect To Virtual Machine Instance

For this step, I have created a Virtual Machine Instance. The public IP for the instance is 34.16.58.106.

Now to connect to this Virtual Machine Instance using MacOS Terminal, the command will be –

ssh -i <LOCATION_OF_THE_KEY>/<PRIVATE_KEY> <USERNAME>@<IP_ADDRESS>

Following the above pattern, command to connect to my Virtual Machine will be –

ssh -i GCP/gcp sudipta@34.16.58.106

This will connect me with my Virtual Machine Instance as you can see below –

Conclusion

I hope this blog post and the video will help you to connect with your Virtual Machine using MacOS Terminal. I know there are people like me who love to work from Terminal. Thank you !!

Disclaimer

This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.

0 Comments

Submit a Comment

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