How to make PuTTY X11 forwarding work in a screen session?
- by Alex Howell
I'm using PuTTY with X11 forwarding enabled, using Xming as my X server on Windows 7.
When I SSH to a Linux host, X11 forwarding works fine.
If I start a "screen" screen manager session, it still works fine.
If I disconnect from the screen session, then later resume in a different PuTTY window using "screen -rd", X11 forwarding doesn't work any more - I get an error:
xterm
X connection to localhost:11.0 broken (explicit kill or server shutdown).
This seems to be because $DISPLAY is different in each PuTTY SSH session (localhost:11.0 in the first session, then localhost:12.0 in the next, and so on). If I manually set $DISPLAY to localhost:12.0 in the screen session, X11 forwarding works again.
Is there a way to automatically set $DISPLAY in the screen session, each time it's resumed, so that it always matches the parent PuTTY session's?