What can I do when my SSH session is stuck? Sometimes my ssh session in the terminal hangs. How can I exit the ssh session and reconnect?
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 command fg to return to the SSH session)


If you want a tilde at the beginning of a line, press ~ twice.