Now Reading
Closing a stale SSH connection

Closing a stale SSH connection

2023-04-09 11:54:04

Suppose you’re related to a distant host with SSH and after some time the SSH
session goes stale. The terminal is unresponsive and no keypress appear to take
impact. There could be one thing with the community, the distant host is
restarting or perhaps your machine has been in hibernation, there could possibly be
a number of causes for a stale session.

The primary resolution that may come to thoughts is to simply shut the terminal
emulator and create one other one, however there’s a higher approach.

SSH escape sequences

Earlier than I present the trick we take a fast detour and discover a sort of hidden
function that’s carried out in most of the out there SSH shoppers.

In-built to the SSH consumer are a number of hidden instructions that may be triggered
with a so known as escape sequence. These instructions could be entry by a
mixture of the tilde prefix (~) adopted by the command.

For instance ~? print the assistance message containing the entire supported escape

david@remote-host:~$ ~?
Supported escape sequences:
 ~.   - terminate session
 ~B   - ship a BREAK to the distant system
 ~R   - request rekey
 ~#   - checklist forwarded connections
 ~?   - this message
 ~~   - ship the escape character by typing it twice
(Word that escapes are solely acknowledged instantly after newline.)

Pay further consideration to the final line;

(Word that escapes are solely acknowledged instantly after newline.)

Which means for the escape sequence to take impact a previous newline is

Additionally, a small be aware for folks utilizing a keyboard with a nordic format; To
sort the tilde character, press AltGr+^ <Area>. I do know that this tripped me
up once I first realized about escape sequences.

See Also

The “terminate session” escape sequence

So, again to the preliminary drawback.

As the assistance message acknowledged above we will shut the session with ~.. And
keep in mind, press enter a few occasions earlier than initiating the sequence:

david@remote-host:~$ ~.
david@remote-host:~$ Shared connection to closed.
david@native:~$ echo $?

From right here we will attempt to provoke the connection once more, or simply reuse the terminal.

Hacker News
Discuss on Hacker News

Source Link

What's Your Reaction?
In Love
Not Sure
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top