Terminating a Hung SSH Session

Discussion in 'Shell / Command Line' started by Eric Hansen, Dec 26, 2013.

  1. Eric Hansen

    Eric Hansen Moderator Staff Writer

    Messages:
    124
    Likes Received:
    87
    Trophy Points:
    28
    More often than not when I leave an SSH session running for a period of time without input the session will hang. By this I mean I can type whatever I want and nothing will echo back. It can be very annoying, especially since I would have to open up a new terminal on my machine, SSH to the server I was on and kill that process.

    There is, however, another trick that I just discovered and can save a lot of extra work. Lets look at the documentation real quick though for SSH to understand how this trick will work:

    By default a pseudo-terminal is always allocated to SSH sessions but if you wish to enforce this pass the "-t" switch when running SSH.

    Above is a list of all the special codes you can use. The one we're interested in is the "~." command.

    If you notice above the list of codes there must be a newline before using the code. Luckily all this means is you hit Enter then the code you want to use (~. in our case). So what you would do is this:
    • Hit the Enter key
    • Hold shift and hit ` (so you send the ~ key)
    • Hit . (period)
    Your session will terminate and you'll be brought back to your regular shell prompt on your local machine.

    Attached Files:

    DevynCJohnson likes this.
  2. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,331
    Likes Received:
    1,069
    Trophy Points:
    113
    I never knew that. Thanks for the good tip.

    Could you do one for Telnet and/or rlogin?
    Haider92 likes this.
  3. Eric Hansen

    Eric Hansen Moderator Staff Writer

    Messages:
    124
    Likes Received:
    87
    Trophy Points:
    28
    As far as I know both are highly recommended NOT to use but when I get the time I will. Right now I'm on my netbook so the available resources to do certain things is a bit more difficult.

    Also, note that this is specific to SSH so there's no guarantee you can do it with Telnet or rlogin. I really don't even know if its possible with Telnet.

Share This Page