Skip to content

Instantly share code, notes, and snippets.

@igaskin
Created October 3, 2021 17:20
Show Gist options
  • Save igaskin/ee2fcbd9033f99f77f4ff44ccd040d64 to your computer and use it in GitHub Desktop.
Save igaskin/ee2fcbd9033f99f77f4ff44ccd040d64 to your computer and use it in GitHub Desktop.
shell script for updating IP in ssh config for Google Cloud Shell
update_cloud_shell_ip () {
IP=$(gcloud alpha cloud-shell ssh --dry-run | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
OLDIP=`grep -w cloud-shell -A 1 $HOME/.ssh/config | awk '/HostName/ {print $2}'`
sed -i "" "s/$OLDIP/$IP/g" $HOME/.ssh/config
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment