DEV Community

chauhoangminhnguyen
chauhoangminhnguyen

Posted on • Originally published at howtodevez.blogspot.com

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.

SSH to VM instance

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
Enter fullscreen mode Exit fullscreen mode

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

VM instances

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
Enter fullscreen mode Exit fullscreen mode

lsb_release

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

sudo passwd
Enter fullscreen mode Exit fullscreen mode

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

vi /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

Edit sshd_config

Find and change the following fields to the following values:

PermitRootLogin yes
PasswordAuthentication yes
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

SSH to a VM Instance

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

VM instances

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

ssh root@34.126.104.206
Enter fullscreen mode Exit fullscreen mode

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

ssh

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.

Remmina connected

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


If you found this content helpful, please visit the original article on my blog to support the author and explore more interesting content.

BlogspotBlogspotDev.toFacebookX


Some series you might find interesting:

Top comments (0)