Skip to content

Instantly share code, notes, and snippets.

@txoof
Last active March 7, 2021 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save txoof/2a1214650c21d6b3ea9cac4d793f2820 to your computer and use it in GitHub Desktop.
Save txoof/2a1214650c21d6b3ea9cac4d793f2820 to your computer and use it in GitHub Desktop.
setup ssh on google cloud instance

Requirements

Enable OS-Login Add SSH-Keys to Project

This only needs to be done once per project

  • gcloud compute project-info add-metadata --metadata enable-oslogin=TRUE --project=<project name>
  • `gcloud compute os-login ssh-keys add --project= --key-file
    • Note down the username in the loginProfile section
    • Usernames are normalized email addresses: foo.bar@gmail.com becomes foo_bar_gmail_com

Connect to remote VM

Connect using a specific key:

  • ssh username@ip -i ~/.ssh/<key_name>

Working with Instances

  • list projects: gcloud projects list

  • set default project: `gcloud config set project

  • list VM instances in default project: gcloud compute instances list

  • stop a VM: `gcloud compute instances stop

  • tab completion supported

  • start a VM: `gcloud compute instances start

  • tab completion supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment