I have some databases that are only accessible via SSH tunnel. Right now, I have to start a tunnel in another tab or the background, then use pgcli to connect to the tunnel locally. When I'm done, I have to remember to kill the tunnel. It would be great if I could pass another argument(s) to pgcli and it would setup and teardown the tunnel for me.
I imagine something like pgcli --ssh 'ssh_user:ssh_password@ssh_host:ssh_port' 'postgresql://pg_user:pg_password@pg_host:pg_port/dbname' which would do the equivalent of:
ssh -p ssh_port -L localhost:0000:pg_host:pg_port -N ssh_user@ssh_host
psql -U pg_user -h localhost -p 0000 -d dbname
where 0000 is some random available port.
sshtunnel looks like it might be well suited to manage the tunnel. It also appears to respect settings in ssh_config(5), so pgcli users with more complicated SSH needs can configure them there.
I have some databases that are only accessible via SSH tunnel. Right now, I have to start a tunnel in another tab or the background, then use
pgclito connect to the tunnel locally. When I'm done, I have to remember to kill the tunnel. It would be great if I could pass another argument(s) topgcliand it would setup and teardown the tunnel for me.I imagine something like
pgcli --ssh 'ssh_user:ssh_password@ssh_host:ssh_port' 'postgresql://pg_user:pg_password@pg_host:pg_port/dbname'which would do the equivalent of:where
0000is some random available port.sshtunnellooks like it might be well suited to manage the tunnel. It also appears to respect settings inssh_config(5), sopgcliusers with more complicated SSH needs can configure them there.