I typically use ssh with connection sharing enabled; this causes any ssh tunnels I create subsequent to the initial ssh login to use that connection. Is it possible to close an ssh tunnel without killing the ssh process in such circumstances?

  • Just to clarify: You close your ssh tunnel by killing the process. Doing that closes all the other sessions that are involved in session sharing on that process. You are looking for a way to close the tunnel in a way that does not affect the other sessions. – TomOnTime Jan 27 '15 at 17:30
  • Yes, that's what I want to do. I tried tracking down the file descriptor associated with the tunnel port and closing that via gdb, but that (perhaps unsurprisingly) caused ssh to die with a "bad file descriptor" error. – lebedov Jan 27 '15 at 17:35
  • I've never tried it, but the -O (capitol O) option seems to let you control the master. The man page isn't clear how it works. – TomOnTime Jan 27 '15 at 17:39
  • What kind of tunnel? -L, -R or -w? – TomOnTime Jan 27 '15 at 17:51
  • I'm starting the tunnel with -L. – lebedov Jan 27 '15 at 17:54

You can terminate all the shared sessions by issuing -O exit from the client side.

ssh -O exit masterhostname

Sadly there is no way to terminate a specific session and leave the others running.

Sessions usually terminate naturally when the session is closed (EOF). Tunnels made using -L and -R are always listening for new sessions and there is no way to indicate they should stop listening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.