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 then
gcloud you got to use
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
gcloudcommand 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 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