Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 couldn't get any program requiring x11 (e.g. gedit, nautilus) to work with sudo. Using gksudo would just fail silently, while on terminal I received the following error:

sudo nautilus

** (nautilus:4160): WARNING **: Command line `dbus-launch --autolaunch=cced40b4aa1d252bc89d3a6a0000000a --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n
Could not parse arguments: Cannot open display: 

With the help of a friend I managed to find a workaround: if I run xhost + as an unprivileged user and then export DISPLAY=:0 as root after a sudo su, it finally works (without the xhost step I'd get an undefined protocol error). However I don't understand why I have this problem in the first place, and it is a laborious workaround - I thought of adding an `export DISPLAY=:0" in root's .bashrc but that's only called if I'm suing, not if I just sudo.

Any ideas on how to properly solve this issue?

share|improve this question
@BenjiWiebe, the thing is that none of this should be necessary in an Ubuntu install. It should work out of the box. Manuhalo, have you changed anything else that might be relevant? Is this a fresh install? Did it used to work? – terdon Dec 4 '12 at 17:43
@terdon it is the machine I use at work, not really a fresh install. I don't remember messing up with /etc/sudoers but then again I might have just forgotten about it. Anyhow, problem solved, thanks a lot! – manuhalo Dec 4 '12 at 17:51
up vote 1 down vote accepted

In general, please remember to include your OS (I imagine you are on Linux) and distribution.

By default, the X server does not allow other users (e.g. root in your case) to connect to an existing X instance. This can be overridden with the xhost + command, after which root can connect to your existing X session.

Exporting DISPLAY should not be necessary, are you sure that it was? You should be ok by simply running xhost + and then sudo gedit or whatever. If that is the case (and you don't mind the slight security risk) you can add xhost + to your ~/.bashrc.

As a horrible workaround, you could run sudo specifying the $DISPLAY variable:

sudo DISPLAY=:0 gedit

To automate, you could add these lines to your ~/.bashrc:

xhost + 
alias sudo='sudo DISPLAY=:0'

This is a horrible hack though, and I would like to know how you managed to get yourself in a situation where it is necessary :). As I said in my comment above, this really should work out of the box on Ubuntu (and most other modern desktop Linux systems). I last had to to fiddle with xhost and DISPLAY when I was working with RedHat about 10 years ago...

share|improve this answer
thanks for your answer, I'm on Ubuntu 12.04 64bit. The DISPLAY export was indeed necessary, as from the error above (and from running echo $DISPLAY) we noticed that that env variable wasn't set for some reason. Adding xhost + in my .bashrc will remove the need for that command, but the problem is actually the DISPLAY export, which needs to be done as root. Ideally I'd like to avoid su-ing into root and just use sudo. – manuhalo Dec 4 '12 at 17:34
@manuhalo Just an idea, did you make sure that DISPLAY was added to the env_keep variable in /etc/sudoers? – BenjiWiebe Dec 4 '12 at 17:37
@BenjiWiebe you are right, that was obviously the right thing to do. Turns out my env_keep only had "http_proxy" for some reason. I'd accept your answer if it wasn't a comment :) – manuhalo Dec 4 '12 at 17:46
@manuhalo Oops. Next time, when I get a brainwave, I will bloat it with unnecessary words and post it as an answer so I will get rep points... and then get downvoted... ;) – BenjiWiebe Dec 4 '12 at 17:48
@BenjiWiebe, I just upvoted another answer of yours (which deserved it anyway) to make up for it :). – terdon Dec 4 '12 at 18:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.