One of the frequently asked questions I receive is how to login to
Google Cloud Linux VM on a custom port using
Google Cloud Platform (GCP) has multiple options to connect to the VM.
changed default SSH port from 22 to something else and trying to connect using then
gcloud you got to use
Let’s see the command syntax.
Login to VM with Custom SSH Port Using gcloud
Log in to Google Cloud Platform and go to
VM instances under Computer Engine Click on the drop-down next to SSH >> view
This will prompt you a small dialog box with a 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"
--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 lets 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. If you are looking to learn more about Google Cloud Platform, then I would recommend this
online course by Dhanaji Musale.
Here’s how to
how to find external IP of Google Cloud VM.