usql icon indicating copy to clipboard operation
usql copied to clipboard

[Feature Request] Connect over SSH

Open conorcamp opened this issue 4 years ago • 3 comments

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.

conorcamp avatar Nov 14 '19 18:11 conorcamp

I'm not likely to implement this. Please note, I'd be glad to entertain a PR enabling this functionality.

kenshaw avatar Nov 14 '19 22:11 kenshaw

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.

nineinchnick avatar Dec 23 '20 20:12 nineinchnick

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

hsanson avatar Oct 02 '23 12:10 hsanson

@kenshaw so is the issue closed because the connection over ssh is implemented, or because it will not be implemented?

strafer avatar Apr 01 '24 06:04 strafer

@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 avatar Apr 01 '24 07:04 kenshaw

@kenshaw thanks, it's clearer now

strafer avatar Apr 01 '24 07:04 strafer

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.

kenshaw avatar Apr 01 '24 07:04 kenshaw

Yes, I use a self-written wrapper based on this mechanism for mycli/pgcli/iredis, apparently I will rewrite it for usql

strafer avatar Apr 01 '24 07:04 strafer