OpenSSH client hangs on logout when forwarding X connections OpenSSH client hangs on logout when forwarding X connections linux linux

OpenSSH client hangs on logout when forwarding X connections


This is because the process you start opens a stream (stdout/stderr) and doesn't close it. Have a look here for a more in-depth explanation and possible solutions.


I know this is an old question but I had the same problem and after doing some digging I found a useful solution. Now I close SSH connections with ~. "terminate connection (and any multiplexed sessions)" and that works for me. The escape character needs to be typed on a new line and in my case the escape character isn't displayed onscreen (I ended up escaping the escape character, i.e. ~~). FYI you can view the forwarded connections from your SSH session with ~#.

For a full list of escape sequences type ~? in your SSH session.

Supported escape sequences:

  • ~. - terminate connection (and any multiplexed sessions)
  • ~B - send a BREAK to the remote system
  • ~C - open a command line
  • ~R - Request rekey (SSH protocol 2 only)
  • ~^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.)


You can send SSH to the background automatically after starting your remote GUI application:

ssh -X -f remote.host.name 'name_of_gui_application'

This will still ask for a password, then run the application and put SSH to the background immediately.

It will also redirect STDIN from /dev/null, so your session will not "hang" after you close the application (not that you'd know, since it is running in the background anyway).

Here's what the manual page of SSH has to say about this:

The recommended way to start X11 programs at a remote site is with something like ssh -f host xterm.