14

I very often SSH into a computer just to send it to sleep. The problem is when it sleeps, it holds the SSH connection open (seemingly indefinitely). Here's what happens:

oli@bert:~$ ssh tank
oli@tank:~$ sudo pm-suspend
[sudo] password for oli:

I put my password in, hit Return and then it hangs... Until I wake the remote machine.

Is there any way to force a disconnect locally so I can get my terminal back without having to close it and start another?

3
  • Oli: Depending on what you are doing, can you use screen or send a command via ssh ? You can also use a key with a forced command.
    – Panther
    Sep 14, 2015 at 16:08
  • 1
    Also see: askubuntu.com/q/35719/158442
    – muru
    Sep 14, 2015 at 16:13
  • How do you wake suspended machine over ssh?
    – Kuntau
    May 19, 2020 at 16:07

1 Answer 1

15

Enter SSH escape codes! From man ssh:

ESCAPE CHARACTERS
 When a pseudo-terminal has been requested, ssh supports a number of
 functions through the use of an escape character.

 A single tilde character can be sent as ~~ or by following the tilde by a
 character other than those described below.  The escape character must
 always follow a newline to be interpreted as special.  The escape
 character can be changed in configuration files using the EscapeChar
 configuration directive or on the command line by the -e option.

 The supported escapes (assuming the default ‘~’) are:

 ~.      Disconnect.

 ~^Z     Background ssh.

 ~&      Background ssh at logout when waiting for forwarded connection /
         X11 sessions to terminate.

So: press Enter~..

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .