Skip to content

Instantly share code, notes, and snippets.

@mdub
Created November 16, 2012 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdub/4082589 to your computer and use it in GitHub Desktop.
Save mdub/4082589 to your computer and use it in GitHub Desktop.
Postgres psql connection via SSH tunnel
#!/bin/sh
db_host=db-server
db_user=supersecret
db_name=myapp_production
port=65432
ssh_ctl=/tmp/$$-ssh-ctl-sock
ssh -S $ssh_ctl -fnN -L $port:localhost:5432 $db_host
trap "ssh -S $ssh_ctl -O exit localhost" EXIT
psql -h localhost -p $port -d $db_name -U $db_user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment