SSH to Google Compute Engine

Introduction

I previously wrote a guide on creating a Virtual Machine (VM) instance on Google Cloud and accessing it via gcloud. However, if your Google Cloud account lacks permission to manage VM instances, or if you want to create a VM instance that allows SSH for easy sharing with other users and compatibility with various SSH tools, follow the steps below.

Configure SSH access for VM instance

Firstly, you need to create a compute instance as follows:

gcloud compute instances create {instance name} \
--zone={zone} \
--machine-type={machine type}

# ex:
gcloud compute instances create instance-1 \
--zone=asia-southeast1-a \
--machine-type=e2-micro


Next, SSH into this VM to perform the necessary configurations.


Typically, a Google VM instance will have a Distributor ID of Debian. Use the following command to check this before proceeding with the next steps.

lsb_release -a


Next, set the password for the root account as follows:

sudo passwd


Next, use the Vim editor to change the settings in the sshd_config file.

vi /etc/ssh/sshd_config


Find and change the following fields to the following values:

PermitRootLogin yes
PasswordAuthentication yes

If you're not familiar with using the Vim editor, you can use the following commands to edit the `sshd_config` file:

- `i`: Switch to interactive mode (allows editing)

- `Esc`: Switch to normal mode (allows using commands)

- `:wq`: Write then quit (saves and closes the file)


After successfully updating the configuration, restart the service.

systemctl restart sshd.service


SSH to a VM Instance

First, you need to obtain the External IP of the VM instance.


To SSH into the VM instance, use the following command:

ssh root@34.126.104.206


After entering your password, the SSH connection will be successful.


You can also use SSH tools or file managers like WinSCP, PuTTY, or Remmina, depending on your needs. These tools make it easy to work with your VM and allow you to save your SSH info for future connections.


Feel free to leave your thoughts in the comments, and don’t forget to like, share, and follow for more great content!

Comments

Popular posts from this blog

Kubernetes Practice Series

Docker Practice Series

NodeJS Practice Series

React Practice Series

Sitemap

Setting up Kubernetes Dashboard with Kind

Deploying a NodeJS Server on Google Kubernetes Engine

Create API Gateway with fast-gateway

Explaining Async/Await in JavaScript in 10 Minutes

A Handy Guide to Using Dynamic Import in JavaScript