Sometimes my ssh session stops working because of the internet connection problem. I tried pressing CTRL+Z and CTRL+C to terminate my ssh session but failed to work. How do I properly kill a hung SSH session without killing my local terminal or using the kill command ? How can I kill unresponsive hung SSH session on macOS?

If the Internet or Intranet connection interrupted the ssh get hung. It is normal and can be mildly infuriating. However, ssh connection comes with escape character support. From the ssh command man page:

ADVERTISEMENTS

When a pseudo-terminal has been requested, ssh supports a number of functions through the use of an escape character. A single tilde character can be sent as ~~ or by following the tilde by a character other than those described below. The escape character must always follow a newline to be interpreted as special. The supported escapes (assuming the default ~) are:

~. Disconnect.

#linux

Linux / UNIX kill unresponsive hung SSH session
2.50 GEEK