Sometimes my ssh session in the terminal hangs. How can I exit the ssh session and reconnect?
Do when the SSH session is stuck
ssh
Related Question
- MacOS – preventing ssh command from opening xquartz on every session
- Can connect over SSH from Mac to linux
- Can a SSH session be wrapped to appear as a distinct App
- MacOS – Terminal displays directory of previous SSH location even when not running SSH
- MacOS – Open an ssh session in terminal with BetterTouchTool
- Open new Terminal in same SSH session
- How to setup ssh so I can ssh back into the local machine
- Detaching Process from “Run Script Over SSH” in Shortcuts
Best Answer
Type
~.
(i.e. tilde, period) at the beginning of a line. In other words, press Enter, then ~, then .. (In some languages, you may need to press Shift or Alt to enter the~
character.)Generally speaking, the
~
character is an escape character in an SSH session when you type it at the beginning of a line. Type Enter then~?
to see the list of escape commands. The most common ones are~.
to terminate the connection~^Z
(press ~ then Ctrl+Z) to suspend the connection and type a command locally (run the commandfg
to return to the SSH session)If you want a tilde at the beginning of a line, press ~ twice.