Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
In Cloud Computing Last updated: November 20, 2022
Share on:
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

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

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


  • 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"

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 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.

  • Chandan Kumar
    As the founder of Geekflare, I’ve helped millions to excel in the digital realm. Passionate about technology, I’m on a mission to explore the world and amplify growth for professionals and businesses alike.
Thanks to our Sponsors
More great readings on Cloud Computing
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • is an all-in-one work OS to help you manage projects, tasks, work, sales, CRM, operations, workflows, and more.
    Try Monday
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder