Possible Duplicate:
How can I break away from an SSH session that has crashed?

I have started an SSH session on the command line, but now I want to get back to my local command line. For any other process, I would hit Ctrl+Z, then run bg. However, the Ctrl+Z get's sent to the remote, rather than the local SSH process. How do I send it to the local SSH process?

marked as duplicate by Alex Chamberlain, Nils, Gilles, Michael Mrozek Jul 9 '12 at 2:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I've found the answer elsewhere, but not until I'd searched for a while. – Alex Chamberlain Jul 5 '12 at 11:18

There is escape char in ssh, by default this is tilde ~. It is recognized only at the beggining of a line.

To suspend your ssh session type ~ then Ctrl+Z.

Refer to the ssh(1) manual under ESCAPE CHARACTERS for more information.

  • 2
    I wasn't typing it at the start of a line... – Alex Chamberlain Jul 5 '12 at 11:52
  • 6
    Incidentally, it's not just any start of a line - you have to have pressed enter right before ~. – Random832 Jul 5 '12 at 14:23

Maybe of less value nowadays, but in my $HOME/.bashrc I aliased ssh to

alias ssh='ssh -e ^]'

That way I avoid potential conflict with ordinary ~ usage albeit fresh after a newline. Instead, to escape out of an ssh session, I press Ctrl ] then Ctrl Z, which coincides with the way we used to do it under old telnet, long ago (or still on some embedded Linux devices, TVs etc. that don't have sshd).

Not the answer you're looking for? Browse other questions tagged or ask your own question.