Forwarding X11 sessions in Ubuntu

After installing a server, I often want to use X11 to do remote display on my desktop. The recommended way to do this is to use "ssh -X <server>" so that the X11 session is tunneled through the encrypted SSH session. (Substitute your server name for "<server>"; no quotes.)

(Note, you can also set X11 forwarding permanently on a machine-by-machine basis by putting commands in "~/.ssh/config"; see "man ssh_config".)

To make this work you need to enable X11 forwarding on the server. Edit "/etc/ssh/sshd_config" and set "X11Forwarding" to "yes".

Now try "ssh -X <server>" and then type "echo $DISPLAY". It should read something like: "<server>:10.0".

Commonly however, the DISPLAY variable will not be set this has generated many many forum posts. (Do a quick Google for "X11Forwarding not working" and you see what I mean.)

The problem has to do with setting up the server, and I have encountered this several times (and usually forgotten why it happens and have to sleuth it again).

If you run "ssh -X -v <server>" it will give some verbose output about the connection. Here are two lines:

debug1: Requesting X11 forwarding with authentication spoofing.
debug1: Remote: No xauth program; cannot forward with spoofing.

So the problem is that SSH forwarding requires the "xauth" program to be installed. On a server without the full desktop installed, "xauth" is generally not there. The solution is:

"sudo apt-get install xauth" (on the server)

Now it will work. Phew!

 

 

|