Created
August 30, 2025 09:54
-
-
Save sloppycoder/d7d666677f57d9e48b4ad1ffde47f13f to your computer and use it in GitHub Desktop.
ssh tmux command into GCP VM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| VM_NAME=$1 | |
| if [ "$VM_NAME" = "" ]; then | |
| echo please specify vm name | |
| exit 0 | |
| fi | |
| USER=$2 | |
| if [ "$USER" = "" ]; then | |
| USER=aidev | |
| fi | |
| # Get zone and IP in one shot | |
| read ZONE IP <<< $(gcloud compute instances list \ | |
| --filter="name=($VM_NAME)" \ | |
| --format="value(zone, networkInterfaces[0].accessConfigs[0].natIP)") | |
| if [ -z "$IP" ]; then | |
| echo "VM $VM_NAME not found or has no external IP." | |
| exit 1 | |
| fi | |
| echo "Connecting to $VM_NAME ($ZONE) at $IP..." | |
| ssh -t "$USER@$IP" 'tmux -CC new -A -s main' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment