Ubuntu – Running X applications on local display from remote host

sshUbuntux11

This is making me frustrated. Why doesn't it work, and how do I get it to work?

I have a newly installed Ubuntu 10.04.2 (Lucid Lynx). I have installed X and gdm. Gdm is set up to automatically log in a user. The computer does not have any keyboard connected, but I want to display some stuff on its local display.

Normally, I would just ssh to the computer as the user who has logged in automatically, and run "DISPLAY=:0.0 xclock", for example.

But now I only get the response:

user@host:~$ DISPLAY=:0.0 xclock
No protocol specified
Error: Can't open display: :0.0

However, if I log in as root, it works.

Best Answer

There seems to be a couple of bugs involved in this problem: This one prevents an .Xauthority file from being created. And this one prevents the proposed workaround from working when using an automatic login.

So the solution was to change the automatic login to a timed login with a short delay, and add the following to /etc/gdm/PostLogin/default

#!/bin/bash

auth=$HOME/.Xauthority
if [ -e $auth ]; then
diff <(xauth extract - $DISPLAY) <(XAUTHORITY=$auth xauth extract - $DISPLAY) > /dev/null && exit 0
fi
xauth extract - $DISPLAY | XAUTHORITY=$auth xauth merge -
chown $USER $auth