Skip to content

Instantly share code, notes, and snippets.

@mdub
Created Nov 16, 2012
Embed
What would you like to do?
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