Why does ssh X forwarding timeout after a while?

26

9

So I have a mac at work which I like to ssh into my linux box with something like this:

$ ssh -Xt user@mylinux

I can login and start any X11 apps on my linux box no problem. But after 15 minutes or so, I come back to a session (ssh is still running and connected) and I get:

$ xterm 
xterm Xt error: Can't open display: localhost:12.0

I've tried using -o "TCPKeepAlive yes" or -o "ServerAliveInterval 30", but still get the same behavior.

Is there something in ssh or on the Mac or my linux sshd conf that kills X-forwarding after a period of inactivity?

Larry Kyrala

Posted 2012-03-30T14:12:27.790

Reputation: 373

(would comment on Bob's 2012-11-18 answer, but it won't let me yet) See also https://unix.stackexchange.com/questions/107547/disable-forwardx11timeout-without-forwardx11trusted-in-openssh-client in which we find that you cannot (in 2019) disable this timeout, but you can extend it. The maximum timeout is uint_max of milliseconds minus some slack, just over 24 days. OpenSSH_7.4p1 will accept ssh -o ForwardX11Timeout=2147423s -X ... which is the best answer I can make now. ForwardX11Timeout above this may crash the XServer in some version combinations. On MacOS with XQuartz, I have seen `Warni

– mcast – 2019-04-24T12:27:10.990

Is the X server still running? Do existing X apps get killed? – Ignacio Vazquez-Abrams – 2012-04-01T08:01:24.097

Answers

28

The default ForwardX11Timeout is 20 minutes for ssh -X, but you can set it to something large (e.g. 7d for 7 days) in .ssh/config

"Trusted" X11 forwarding via ssh -Y actually enables potentially nasty things like keystroke monitoring and screen grabs.

Bob

Posted 2012-03-30T14:12:27.790

Reputation: 296

3man ssh_config for this option documentation :) – drAlberT – 2013-05-27T16:17:17.910

20

Using -X, X11 forwarding is enabled in "Untrusted" mode, making use of various X11 security extensions, including a time-limited Xauth cookie.

Use -Y to enable "Trusted" mode for X11, which will enable complete access to your X11 server.

user1686

Posted 2012-03-30T14:12:27.790

Reputation: 283 655