usql
usql copied to clipboard
[Feature Request] Connect over SSH
Would be nice if there was a native way to configure connections to use an SSH tunnel (similar to how MySQL Workbench and other GUI clients allow you to do this). I know this can be set up manually, but managing the lifecycle of one or many ssh tunnels can be very annoying.
I'm not likely to implement this. Please note, I'd be glad to entertain a PR enabling this functionality.
You could configure systemd to open up SSH tunnels on demand, when you'd try connecting to a local port. I found an example article that describes this: https://p5r.uk/blog/2017/smtp-via-ssh-tunnel.html It mentions SMTP but could be easily adjusted to connect to databases.
Potential tips on how to support this for anyone with enough Go knowledge to implement it:
- SQLS supports SSH tunneling:
- https://github.com/lighttiger2505/sqls/blob/master/internal/database/mysql.go#L73
- https://github.com/lighttiger2505/sqls/blob/master/internal/database/postgresql.go#L63
- SSHDB seems to provide generic ways to support this
- https://github.com/jfcote87/sshdb
@kenshaw so is the issue closed because the connection over ssh is implemented, or because it will not be implemented?
@strafer I'm not planning on implementing this, no. If someone wants to write it and submit a PR, I would consider merging it.
@kenshaw thanks, it's clearer now
Please note that there are many mechanisms to open a tunnel via SSH that are easy and straightforward:
$ ssh -L 8080:localhost:8080 user@remotehost:port
As as this would require a large amount of coding, and I'm not really sure if it falls within the category of what usql
"is", it's not something I have any plans of working on. As I said, if someone wanted to hack this out, I'd be glad to accept a well written PR.
Yes, I use a self-written wrapper based on this mechanism for mycli/pgcli/iredis, apparently I will rewrite it for usql