Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run open a GUI program on a remote Ubuntu machine using ssh.

I want to open, lets say Firefox or Skype, on a machine I have connected to via ssh. But when writing logging in with user2 and writing sudo -u user1 firefox I get an error message saying no display specified.

The machine is turned on and logged in with user1, it just appears that i cant get ubuntu to recognize that there is a GUI available.

I wouldnt mind alternative solutions but I would prefer help with this specific scenario.

share|improve this question

Set X11Forwarding yes in configuration file for SSH server (/etc/ssh/sshd_config). Restart server and run ssh on client machine with -X or -Y option (this should work with OpenSSH).

share|improve this answer
I forgot to mention that i want the program GUI to launch on the remote machine. – Martin May 8 '11 at 10:51
dbus-launch firefox&

This has worked for me in the past from a shell, you could give it a try via SSH.

share|improve this answer

The use of sudo complicates things a bit and will require a few extra steps.

If you've setup your /etc/ssh/sshd_config as others have mentioned with

X11Forwarding yes

then ssh'n into the box as user2 via

$ ssh -YC

You should be able to run remote X apps as user2. A simple way to test this on a lot of X based systems is to run

$ xlogo

It's very lightweight compared to something like firefox though firefox will work as well.

Once you are certain X is working via your remote ssh connection as user2 we can make it work with the sudo to user1. The problem is that when you sudo to user1 you are losing authority to use your remote X forwarding. To get around this, first as user2 do the following after logging in

$ echo $DISPLAY
$ xauth list
carlisle/unix:17  MIT-MAGIC-COOKIE-1  161bda5fc81200a4e74e578009177fb8

You should see a line that contains the same display number, in my example it's 17. You'll want to find the matching number in the xauth list output. Next sudo to user1 and run an xauth add command to add the auth line that matched above

$ sudo su - user1
$ xauth add carlisle/unix:17  MIT-MAGIC-COOKIE-1  161bda5fc81200a4e74e578009177fb8

You should now be able to run any app you want.

$ xlogo  # or any X app such as firefox 

If you get an error about being unable to lock ~user2/.Xauthority you will need to adjust permissions on that file prior to using sudo to switch to user1. It's not exactly secure but you could set the file permissions to chmod 666 on that file to test.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .