Skip to content

Google Cloud SSH Keys Metadata-Managed Project Level

Step-01: Introduction

  1. Metadata-managed SSH Connections
  2. Automatically Configured at Project Level: Temporarily grant a user access to an instance (so far we are using this one)
  3. Manually Managing SSH Keys in Metadata: Generate SSH keys and upload to Project Medatada
  4. Instance-Level Public SSH Keys
  5. OS Login-managed SSH connections (Google Recommended)
  6. In this section, we are going to focus on SSH Keys Metadata-Managed at Project level

Step-02: Create SSH Keys Manually - Public and Private Key

  • Risks of Manual Key Management
    # Switch Directory
    cd ssh-keys
    
    # Generate SSH Keys
    ssh-keygen -t rsa -f ssh-keys-custom -C sshcustomuser1
    
    # File Names
    SSH Private Key: ssh-keys-custom
    SSH Public Key: ssh-keys-custom.pub
    
    # Restrict access to your private key so that only you can read it and nobody can write to it
    chmod 400 ssh-keys-custom
    
    # Copy content from ssh-keys-custom.pub
    cat ssh-keys-custom.pub
    

Step-03: Upload Custom SSH Public Key and Username to GCP Project Metadata

  • Go to Compute Engine -> Metadata -> SSH Keys -> Edit
  • Click on Add Item
  • Copy content of file ssh-keys-custom.pub to text box, automatically username will be populated, and click on Save
  • Refresh browser to see sshcustomuser1 public key present in Metadata.

Step-04: Connect using your Local Desktop Terminal

# Connect from MacOS / Windows10 CMD line
cd ssh-keys
ssh -i ssh-keys-custom <USER-FROM-SSH-KEYS>@<VM-Public-IP>
ssh -i ssh-keys-custom sshcustomuser1@104.198.236.153

Additional References

🎉 New Course
Ultimate DevOps Real-World Project Implementation on AWS
$15.99 $84.99 81% OFF
DEVOPS2026FEB
Enroll Now on Udemy
🎉 Offer