Skip to content

Setup and teardown an SSH tunnel #459

@cbandy

Description

@cbandy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions