Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have open tunnel with

ssh -2 -N -L 5001:localhost:1019 eonil@test.local

The tunnel is working good, but I have to Ctrl+C or Ctrl+D to force quit the tunnel. How can I close the tunnel gracefully?

share|improve this question

SSH has a escape sequence to reset the connection, it will probably work for what you want. Press enter, then ~., yes it's enter tilde-dot.

It also works when you have a hanged SSH connection (like a connection that timed out but didn't close), just press enter (I have an habit to press it more than once) and the tilde-dot sequence to close it.

Some useful ones:

  • ~? will show you all the escape sequences available
  • ~^Z that's control+Z will suspend your SSH session (you can get it back with fg)
share|improve this answer
How can I send the command to the tunnel connection? It does not accept local console input anymore. – Eonil Mar 11 '11 at 3:19
Hmm. Yes, you need to have it open (accepting input, not using -N). With input available you can even create more tunnels without running the command again (check the escape sequences about it). – coredump Mar 11 '11 at 3:26
great answer. – Registered User Mar 11 '11 at 11:41

Close whatever is connected with the other side through the ssh connection first.

share|improve this answer
I used NFS over tunnel, but the tunnel does not being closed after I unmounted the volume. – Eonil Mar 11 '11 at 2:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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