Skip to main content
11.03.2026

SSH Escape Sequences: The Hidden Commands Every SRE Should Know

head-image

Every SRE has experienced it: a hung SSH session that refuses to respond. You mash Ctrl+C repeatedly, but nothing happens. The connection is dead, but your terminal is stuck. There is a better way.

SSH includes a set of escape sequences that give you control over your session without needing to close your terminal. These commands work in any standard OpenSSH session and can save you significant time during incident response.

How Escape Sequences Work

SSH escape sequences start with a tilde (~) character. The key detail: the tilde must follow a newline. Press Enter first, then type the escape sequence. If you need to send an actual tilde, type ~~.

The default escape character can be changed with ssh -e or the EscapeChar config option, but most systems use tilde.

Essential Escape Commands

Here are the sequences you should memorize:

  • ~. - Disconnect immediately. The nuclear option for frozen sessions.
  • ~^Z - Background the SSH session (Ctrl+Z equivalent).
  • ~# - List all forwarded connections. Great for debugging tunnels.
  • ~? - Show all available escape characters.
  • ~C - Open the SSH command line for dynamic port forwarding.
  • ~& - Background SSH while waiting for forwarded connections to close.
  • ~R - Request connection rekeying for long-running sessions.
  • ~v / ~V - Increase or decrease verbosity for debugging.

Adding Port Forwards Without Reconnecting

The ~C escape opens an interactive command line. From there, you can add new port forwards without disconnecting:

# Press Enter, then ~C
ssh> -L 8080:localhost:80
Forwarding port.

ssh> -R 9090:localhost:3000
Forwarding port.

ssh> -KL 8080
Canceled forwarding.

This is invaluable during incident response when you suddenly need to access an internal service through your existing jump host connection.

Practical Tips

Debugging tunnel issues: Use ~# to list active forwards. This shows which ports are actually forwarded and helps identify misconfigurations.

Graceful disconnect: When running long processes, ~& lets SSH wait for forwarded connections to finish before closing, preventing dropped tunnels.

Session stuck?: Always try ~. before killing your terminal. It cleanly disconnects and avoids orphaned processes.

Conclusion

SSH escape sequences are one of those features that seem obscure until you need them. Memorizing ~. alone can save you from countless frozen terminal situations. The ability to dynamically add port forwards with ~C makes SSH even more powerful for ad-hoc infrastructure access.


Akmatori helps SRE teams automate incident response and runbook execution with AI agents. Check out akmatori.com to see how autonomous agents can handle your operational tasks, or deploy on Gcore for global edge infrastructure.

Automate incident response and prevent on-call burnout with AI-driven agents!