Ubuntu – open terminal via ssh run firefox -> display not found

firefoxseleniumsshUbuntux11

I want to run selenium tests on a Hudson slave.
The slave (i.e. the machine) that will execute the selenium is a Ubuntu 10.04.
Thus it has Gnome. Selenium needs a firefox to run.

What Hudson does now is, it creates a ssh connection to the Ubuntu machine and launches selenium there. Selenium tries to start a firefox.

And now it blames:

Error: cannot open display

What needs to be done that the 'ssh shell' gets a display from the X-server?

Best Answer

Make sure that the remote machine has ssh X11 forwarding enabled:

$ grep X11 /etc/ssh/sshd_config 
X11Forwarding yes
X11DisplayOffset 10
$

Use ssh -X user@remote_machine to connect to remote machine. If on remote machine you are using a different user to start the X client, use xauth list to get the current credentials in the ssh user, then use xauth add to add the credentials to the user you are becoming with sudo/su.

read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $u