Hark! Thou may find thyself typing in a remote SSH session, when suddenly, all falls silent. The system doth not respond to thy keystrokes. What shall thou do in such a dire situation?
Herein lies the cause of this phenomenon, a guide on how to part ways with an unresponsive SSH session, and why thou should consider embracing Mosh.
What Causes SSH Sessions to Freeze?
The primary reason betwixt frozen SSH sessions is a drop in the network connection. Wi-Fi signals may falter, or perhaps thou hath allowed thy computer to slumber. ‘Tis most common with laptops. Forsooth! Thou might close the lid of thy laptop whilst forgetting thou art still logged in via SSH.
SSH was initially crafted in an era ere laptops were commonplace. It doth function more smoothly over wired networks.
1. Terminate With an Escape Sequence
In the event thy SSH session doth freeze, endeavor to employ an escape sequence. Such a sequence allows thee to dispatch signals to the SSH client, rather than the remote machine. Prefaced by an escape character, escape sequences art heralded by the tilde (~) character by default on the OpenSSH client.
To bid adieu to the SSH client, thou may press the tilde key followed by the period (.) key.
2. Using the kill Command
If the utilization of an escape sequence doth not avail thee, thou canst attempt to slay the SSH client. To unearth the process ID (PID) of thy session, pipe the ps command through grep:
ps aux | grep ssh
The argument ‘aux’ in ps signifieth ‘list every process on the system, regardless of owner or possession of a controlling terminal.’ Shouldst thou possess multiple sessions, thou may discern the frozen one by perceiving the username and address on the remote machine to which the SSH sessions art logged. Once the PID of thy session is unearthed, thou canst terminate it with the kill command:
kill [PID]
For Better SSH Connections, Use Mosh!
A superior method to avoid vexatious frozen SSH sessions is to champion Mosh. Should the connection falter, Mosh shalt permit thee to remain connected, dispatching any messages upon reconnection. It also thrives when thy machine doth slumber.
One may also employ a terminal multiplexer such as GNU Screen or tmux to resume an SSH session subsequent to disconnections, but Mosh and tmux together art yet more potent.
To install Mosh on Debian or Ubuntu:
sudo apt install mosh
And on Arch Linux:
sudo pacman -S mosh
On the Red Hat clan of distros:
sudo dnf install mosh
Now Thou Canst Be Rid of Stuck SSH Sessions
Unresponsive SSH sessions canst be vexing, but with an escape sequence or the kill command, thou canst vanquish them. Mosh stands as an even superior alternative, steadfast in maintaining thy connection through drops and slumbers.
Support our work ❤️
If you enjoyed this article, consider leaving a tip to help us keep publishing great content.



























