Killing a dead ssh connection

One feature telnet has and I always missed from ssh was the ^] shortcut, giving you a way to terminate the connection.

ssh has a similar feature. If you setup 'escape characters', you can terminate the connection by typing '~.' Just add the following to your .ssh/config:

  1. Host *
  2. EscapeChar ~

You can change the character here too, but ~ is the default and a sensible one.

If you're dealing with crappy ssh connections that often terminate, you can add the following to make the client send a keep-alive package every 60 seconds:

  1. Host *
  2. ServerAliveInterval 60

5 Responses to Killing a dead ssh connection

  1. 6190 david 2010-09-27 10:38 am

    with regards to terminating a ssh connection does 'ctrl+d' not do what you are after?

  2. 6196 Evert 2010-09-27 6:01 pm

    No, ctrl+d is sent to the server. That's why you can place jobs in the background while being connected, instead of putting the ssh client itself in the background.

  3. 6203 Alan Knowles 2010-09-28 1:11 am

    have you tried 'screen' a really nice way to put stuff in the background, and then terminating normally with ctrl-d

    Funnily only discovered that one after I found it running on a server which was broken into ;)

  4. 6207 Evert 2010-09-28 6:39 am

    I actually tend to start screen when I'm already logged in, not before I log in. The main difference is that it allows me to resume my ssh session on the client, and ctrl-d won't work in those cases =).

  5. 6464 Fake51 2010-10-10 3:48 pm

    There's no need to add the settings to your .ssh/config - ssh by default uses '~' as escape char.

Leave a Reply



About

My name is Evert, and I've been writing semi-regularly on this blog since 2006.

I'm currently available for contract work.

more info.

Subscribe

Dropbox

Dropbox is a simple cross-platform online backup and sync application. The first 2GB of space is free, and both you and me get an extra 250MB extra space if you sign up through this link.