Your SSH session is frozen. You type, nothing echoes. Ctrl+C does nothing, exit does nothing, and the only thing that seems to work is closing the whole terminal window. There is a faster way out: press Enter, then ~, then . and the OpenSSH client drops the connection on the spot, no matter how dead the network is.
This guide covers that escape sequence and the reasons it sometimes doesn't work, the four usual causes of a frozen SSH session, how to tell them apart, and the settings that stop it from happening again. Every client message quoted below was reproduced on a lab sshd running OpenSSH 9.6p1 on Ubuntu 24.04, with an iptables rule standing in for a dead network.
Quick Summary: What You'll Learn
- The three keys that kill a frozen SSH session, and why they work when nothing else does.
- The other escape sequences worth knowing (
~?,~#,~C,~~). - Why
~.sometimes does nothing, with a fix for each case. - The four common causes of a frozen session, including the one that isn't a network problem at all (
Ctrl+S). - How
ServerAliveInterval, tmux and mosh stop a freeze from costing you work.
How do you exit a frozen SSH session?
Press these three keys in order:
Enter ~ . That is a newline, a tilde, then a period. The OpenSSH client watches your keyboard input for its escape character, ~, at the start of a line. When it sees ~. it closes the connection itself, locally. It doesn't send anything to the server or wait for an answer, so it works even when the server or the network in between is gone.
In the lab, the network path was cut with a DROP rule while a session was open. A command typed after that never echoed back. Then Enter ~ . gave this, immediately:
root@hermes:~# Connection to 127.0.0.1 closed. The ssh process exited with status 255. Per the man page, ssh returns the remote command's exit status, or 255 if an error occurred. Your local terminal is back and you can reconnect.
The leading Enter matters. The ssh(1) man page says the escape character "is only recognized at the beginning of a line". If you already typed something on the current line, the client treats ~. as normal text. Pressing Enter first guarantees you're at the start of a new line.
A note for some keyboard layouts: on layouts where ~ is a dead key (US-International and several European layouts), the tilde may wait for the next keystroke before it's sent. If ~. seems to do nothing, check that a single ~ actually appears when you type it at a normal prompt.
Which other SSH escape sequences are useful?
Type ~? at the start of a line to print the list your client supports. On OpenSSH 9.6 it prints:
Supported escape sequences: ~. - terminate connection (and any multiplexed sessions) ~B - send a BREAK to the remote system ~R - request rekey ~V/v - decrease/increase verbosity (LogLevel) ~^Z - suspend ssh ~# - list forwarded connections ~& - background ssh (when waiting for connections to terminate) ~? - this message ~~ - send the escape character by typing it twice (Note that escapes are only recognized immediately after newline.) The ones you'll actually use:
-
~.closes the connection. Note the "(and any multiplexed sessions)": if you share connections withControlMaster, every session riding on that master goes down with it. -
~^Z(tilde, thenCtrl+Z) suspends thesshclient and drops you to your local shell.fgbrings it back. Handy when you need a local command without opening a new tab. -
~#lists forwarded connections, useful when a port forward seems stuck. -
~Copens a small command line where you can add a forward (-L,-R,-D) or cancel one (-KL,-KR,-KD) without reconnecting. It's missing from the list above because it's off by default in current OpenSSH;EnableEscapeCommandline yesin your config turns it back on. -
~~sends a literal tilde. This is the key to nested sessions.
How do you exit a nested SSH session without killing the outer one?
If you SSH into a bastion and from there into another server, both ssh clients watch for ~ at the start of a line. Your local client sees it first, so ~. kills the outer connection and everything inside it.
To reach the inner client, double the tilde: Enter ~ ~ .. Your local client turns ~~ into a single ~ and passes it on, and the inner client sees ~. and closes. In the lab, ~~. closed the inner session, the prompt of the outer host came back, and a command run there worked normally. Each extra hop needs one more tilde.
If you jump through bastions often, ssh -J avoids the nesting problem entirely, since there is only one interactive client. Our bastion host and ProxyJump guide covers the setup.
Why is the SSH escape sequence not working?
There are three common reasons, and all three were reproduced in the lab.
You weren't at the start of a line. Typing x~. sends the three characters to the server as ordinary input. The client only acts when ~ directly follows a newline. Press Enter first. If the session is truly frozen, the Enter goes nowhere, but the client still counts it.
There is no pseudo-terminal. The man page says escape sequences work "when a pseudo-terminal has been requested". A plain interactive login gets one. A command such as ssh host 'tail -f /var/log/syslog' does not, unless you add -t. In the lab, a ~. piped into a session without a pty went straight through to the remote program as data, and the session carried on. For long-running remote commands, use ssh -t host '...' if you want the escape available.
The escape character is disabled or changed. EscapeChar none in ~/.ssh/config (or ssh -e none) turns escapes off completely; the man page calls it a "fully transparent" session. With that set, the lab's ~. arrived at the remote shell as a command, which answered with "command not found". Some tools set this on purpose, for example when they pipe binary data over SSH. Check with:
ssh -G yourhost | grep -i escapechar ssh -G prints the configuration the client would use for that host without connecting. The default value is ~.
If you prefer a different escape key, set it per host in your config. Our SSH config organization guide shows how to keep per-host settings like this tidy.
Why does an SSH session freeze in the first place?
A session that "freezes" is almost always one of four things. Only the first one is really an SSH problem.
1. The network path died silently
The most common case. Your laptop slept, you switched Wi-Fi networks, a VPN reconnected, or a NAT router or firewall between you and the server forgot about the connection after it sat idle. TCP doesn't announce any of this. Your client keeps a socket that looks open, and the first sign of trouble is that your keystrokes stop echoing.
Without keepalives, nothing will tell the client the connection is gone until it tries to send data and the operating system eventually gives up on retransmitting. That can take many minutes, which is why the terminal appears to hang. This is also why you see "client_loop: send disconnect: Broken pipe" or "Connection reset" when you come back to a session after lunch.
2. You pressed Ctrl+S
This one fools experienced people. In a Unix terminal, Ctrl+S sends XOFF, which tells the terminal to stop output. Flow control is on by default on most Linux systems: stty -a on the lab server showed ixon, which stty(1) describes as "enable XON/XOFF flow control".
The connection is fine. Your keystrokes still reach the server, and the commands still run. You just can't see any output. In the lab, after Ctrl+S, a typed echo command and its output never appeared on screen. After Ctrl+Q (XON), the hidden output appeared at once.
So before anything else, press Ctrl+Q. It's harmless if flow control wasn't the cause. If you hit Ctrl+S by accident often (it's the save shortcut in many editors), turn flow control off in your remote shell's startup file:
# ~/.bashrc on the server, interactive shells only [[ $- == *i* ]] && stty -ixon Note that keystrokes typed while output is stopped are still executed. Be careful what you type while you're unsure which case you're in.
3. The server is overloaded or a process is stuck
The network is up, but the server can't respond: it's out of memory and swapping, the disk is saturated, or the program in the foreground ignores Ctrl+C. Characters may echo slowly or not at all. Unlike a dead network, this often recovers by itself, and keepalives won't kill it, because the server's SSH daemon may still answer them.
Open a second session to the same host. If it connects but is slow, look at top or free -h. If it doesn't connect at all, the server or its network is the problem, not your session.
4. The terminal itself is in a bad state
If you cat a binary file or a program crashes in the middle of drawing a full-screen interface, your local terminal can be left in a strange mode: no echo, garbled characters, or keystrokes that seem to vanish. The session is alive. Type reset and press Enter (blind, if necessary). It reinitializes the terminal.
How do you tell which kind of freeze you have?
Work through this in order. It takes under a minute.
- Press Ctrl+Q. If output comes back, it was flow control.
- Press Enter, then type
~?. If the escape list appears, your localsshclient is alive and reading your keyboard. This alone doesn't prove the network works, because the list is printed locally. - Type a short command and wait about ten seconds. If it echoes, even slowly, the connection works and the server is busy (cause 3) or your terminal is confused (cause 4).
- If nothing echoes, open a new SSH session from another terminal. If the new session connects quickly, the old connection was cut somewhere along the way (cause 1). Kill it with
~.. If the new session hangs before the prompt, it's a connection-level problem. Our guide to connection refused vs. connection timed out explains how to read those errors, and the EC2 SSH timeout guide covers the cloud-specific causes.
How do you stop SSH from freezing after inactivity?
Make the client notice dead connections, and keep idle connections visibly busy for the routers in between. OpenSSH does both with server alive messages. Add this to ~/.ssh/config:
Host * ServerAliveInterval 60 ServerAliveCountMax 3 From ssh_config(5): ServerAliveInterval is the number of seconds without data from the server after which the client sends a message through the encrypted channel asking for a response. The default is 0, which means never. ServerAliveCountMax is how many of those may go unanswered before the client disconnects (default 3).
With the values above, a dead connection is detected after roughly three minutes, and an idle session sends a small packet every minute. That traffic usually keeps NAT and firewall idle timers from expiring in the first place. In the lab, with short test values (ServerAliveInterval 3, ServerAliveCountMax 2) and the network cut, the client gave up within seconds:
Timeout, server 127.0.0.1 not responding. You can configure the same thing on the server for every client with ClientAliveInterval and ClientAliveCountMax in sshd_config. ClientAliveInterval also defaults to 0, which means off. Server-side settings help when you can't control every client, and they let the server clean up sessions from clients that vanished.
Keepalives have limits:
- They don't keep a session alive while your laptop sleeps. Nothing is sent while the machine is suspended, and the server may give up on you in the meantime.
- They don't survive an IP address change. A TCP connection is tied to your old address. Switch networks and the session is gone, keepalives or not.
- They turn a silent hang into a clean error. That's the real benefit: you find out in a minute or so instead of staring at a frozen window.
How do you keep your work when the connection dies anyway?
Connections will drop. The fix is to make the drop cheap.
Run long work inside tmux (or screen) on the server. The tmux session lives on the server, not in your SSH connection. When the connection dies, kill the frozen client with ~., reconnect, and run:
tmux attach Everything is where you left it, including running jobs and scrollback. If a pane inside tmux looks frozen while the rest of tmux responds, it's usually the program in that pane, or a Ctrl+S in that pane. Try Ctrl+Q there first. Our tmux guide for remote servers covers the setup and the habits that make it stick.
Use mosh on connections that roam or sleep. Mosh logs in over SSH, then, in the project's words, starts "a connection on a UDP port between 60000 and 61000". Its site says it keeps the session through roaming between networks and through laptop sleep, and that the connection resumes when the network comes back. The trade-offs: you need mosh-server installed on the host and those UDP ports open in its firewall, and anything that relies on the SSH connection itself, such as port forwards, still needs plain ssh. Many people combine both: mosh for the connection, tmux for the work.
Where does termique fit?
termique is a free, native SSH manager with end-to-end encrypted credentials, for macOS, Windows, Linux, iOS and Android. A few things in it relate directly to frozen sessions:
- Closing a hung session is a click. Each session has a Close session button in its header, and the session's tab can be closed from the sidebar. That disconnects it and discards its scrollback. The host itself stays saved.
- The session state is visible. A status dot and banner show whether a session is connecting, connected, disconnected or failed, with a Reconnect or Retry button.
- Port forwards reconnect on their own. When a forward's connection drops, termique retries, waiting 2 seconds at first and up to 30 seconds between attempts.
To be clear about the limit: per the docs, termique does not reconnect a dropped terminal session by itself. You click Reconnect. So the advice above still applies: run anything that matters inside tmux on the server, and reattach after reconnecting.
FAQ
How do I exit a frozen SSH session?
Press Enter, then ~, then .. The OpenSSH client closes the connection locally without waiting for the server, so it works even when the network is dead. If you're in a nested session, use ~~. to close only the inner one.
Why does my SSH session freeze after inactivity?
Usually a NAT router, firewall or VPN between you and the server drops idle connections without telling either side. Set ServerAliveInterval 60 in ~/.ssh/config so the client sends regular messages through the connection and notices quickly when it's gone.
What does ~. do in SSH?
It's the OpenSSH escape sequence for "disconnect". The client recognizes ~ at the start of a line as its escape character, and ~. makes it terminate the connection, including any sessions multiplexed over it. ~? lists all supported escapes.
Why is the SSH escape sequence not working?
The ~ must come right after a newline, so press Enter first. Escapes also only work when the session has a pseudo-terminal (add -t for remote commands), and they're off entirely if EscapeChar none is set. Check your effective setting with ssh -G host | grep -i escapechar.
How do I disconnect from an SSH session normally?
Type exit or logout, or press Ctrl+D on an empty prompt. These end the remote shell, and the connection closes after it. Use ~. only when the session doesn't respond to those.
Try termique
If you manage more than a handful of servers, download termique: keep your hosts organized, reconnect with one click, and sync your credentials across devices with end-to-end encryption. It's free to start.


