Skip to content

Instantly share code, notes, and snippets.

@sarah-j-smith
Created January 12, 2021 01:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sarah-j-smith/6fe9dc90204b39edd61eb2b111b2de4e to your computer and use it in GitHub Desktop.
Save sarah-j-smith/6fe9dc90204b39edd61eb2b111b2de4e to your computer and use it in GitHub Desktop.
Connect to Google Cloud Compute instance via SSH using OS-Login
# Creates a portable SSH key that can be offered to any GCP Compute instance you have access to, eg via Google domain login
# Pre-requisites - gcloud Google command line tool. - https://cloud.google.com/sdk/docs/quickstart
curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-322.0.0-darwin-x86_64.tar.gz -o google-cloud-sdk.tar.gz
open -g google-cloud-sdk.tar.gz
./google-cloud-sdk/install.sh
source ~/.bash_profile
# Setup Google login, compute zone, region and project
gcloud init
# If don't have keys then create them - do NOT enter a password
ssh-keygen ~/.ssh/id_rsa_gcp
# Add ssh keys to OS Login
gcloud compute os-login ssh-keys add \
--key-file=~/.ssh/id_rsa_gcp.pub
# From now are all set up - the below command is all that is needed from now
ssh -i ~/.ssh/id_rsa_gcp sarah_smithsoft_com_au@35.227.186.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment