rgzr / sshtun

Go package to create SSH tunnels
MIT License
89 stars 13 forks source link

Reverse tunnel #10

Open Roemer opened 1 year ago

Roemer commented 1 year ago

Is it possible to create a reverse tunnel with this library and if so, could you provide an example?

rgzr commented 1 year ago

That feature is not implemented in this library. But it should not be that hard to implement. You can find a reference here: https://gist.github.com/codref/473351a24a3ef90162cf10857fac0ff3

Roemer commented 1 year ago

All references I found have issues with not correctly closing connections, keeping them open for too long or printing exceptions or no exceptions at all. Like (as you mentioned) here: https://gist.github.com/codref/473351a24a3ef90162cf10857fac0ff3 or here https://stackoverflow.com/questions/21417223/simple-ssh-port-forward-in-golang or here https://stackoverflow.com/questions/74227986/golang-ssh-tunneling-and-proxyjump or here https://eli.thegreenplace.net/2022/ssh-port-forwarding-with-go/ or here https://ixday.github.io/post/golang_ssh_tunneling/ or here https://codref.org/rated-d/go-implementation-of-a-reverse-ssh-tunnel/

The best variant I found is either this library or https://gist.github.com/0187773933/0f1061d6ada5333dbe462ae2bacd7bbd, which uses Once and WaitGroup to correctly handle the situation.

rgzr commented 1 year ago

Yes maybe those are not very polished, but are a good starting point. I don't have time now for implementing this, but collaboration is welcome and maybe I will do it in the following months.