Google Cloud

One of the frequently asked questions I receive is how to login to Google Cloud Linux VM on a custom port using gcloud.

Google Cloud Platform (GCP) has multiple options to connect to the VM.

If you’ve changed default SSH port from 22 to something else and trying to connect using thengcloud you got to use --ssh-flag parameter.

Let’s see the command syntax.

Login to VM with Custom SSH Port Using gcloud

  • Login to Google Cloud Platform and go to VM instances under Computer Engine
  • Click on drop-down next to SSH >> view gcloud command

This will prompt you a small dialog box with command, something like below.

gcloud compute --project "PROJECT_NAME" ssh --zone "us-central1-b" "instance-1"
  • If you notice, custom SSH port is not defined in the command, and you have to add it manually.
  • Let’s assume SSH port is 2222 so gcloud command would be like below.
gcloud compute --project "PROJECT_NAME" ssh --zone "us-central1-b" "instance-1" --ssh-flag="-p 2222"

By adding --ssh-flag you instruct gcloud to connect the VM instance on a given port number instead of default one.

Login to VM with Custom SSH Port through Browser

Not using gcloud or SSH client? don’t worry.

GCP let you access your VM directly through the browser. Go to VM instances and under SSH drop-down, select “Open in a browser window on a custom port.”

Enter the port number and click “OPEN”

You will have your VM SSH session in the browser

I hope this quick guide helps you. /kswallet

Related Posts
Not every application can be hosted on Linux, or not everyone likes or comfortable with
Security is essential for any website to provide security, build the trust of visitors, and for better
Having default product error page from Apache HTTP or Nginx doesn’t look good and it
Optimization is one of the essential exercises for website owners and bloggers. Without right optimization,