Skip to content

Instantly share code, notes, and snippets.

@rosenhouse
Last active December 23, 2015 20:59
Show Gist options
  • Save rosenhouse/6693251 to your computer and use it in GitHub Desktop.
Save rosenhouse/6693251 to your computer and use it in GitHub Desktop.
echo "Connecting to bastion via SSH..."
ssh -nNf bastion
echo "Connecting to MySQL..."
mysql -ugabe -pPaS$w0rD -h127.0.0.1 my_database
echo "MySQL client terminated, closing SSH connection..."
ssh -O exit bastion
echo "Done."
# put this in ~/.ssh/config
Host bastion
HostName bastion.example.com
IdentityFile ~/.ssh/my-private-key
LocalForward 3306 db-server.local:3306
User gabe
ControlMaster auto
ControlPath /tmp/ssh-%r@%h:%p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment