Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When I am running some software using sudo command it showing error like

cannot connect to X server

For example if I run the following command:

$ sudo gedit /etc/profile

I am getting following command

(gedit:6758): WARNING **: Command line `dbus-launch --autolaunch=84b871d735f31ffe014dc9ba00000009 --binary-syntax --close-stderr' 
exited with non-zero exit status 1: 
Autolaunch error: X11 initialization failed. 
Cannot open display:
Run 'gedit --help' to see a full list of available command line options.

Or if I am running super-boot-manager I am getting following error

buc: cannot connect to X server

Please help.

share|improve this question
    
Where do you run super-boot-manger from? –  Thor Aug 15 '12 at 9:49
    
First I have tried to run super-boot-manager directly from unity luncher, it did not worked. Then I have tried it from terminal, then I got those error massage. –  Apurba Aug 15 '12 at 13:21
    
As in a terminal within the graphical user environment? What does: echo $DISPLAY say? You should run it without sudo as super-boot-manager runs sudo internally. –  Thor Aug 15 '12 at 15:23
    
echo $DISPLAY is giving :0.0. And I am not running super-boot-manager as sudo. I am running just using command super-boot-manager from terminal. –  Apurba Aug 16 '12 at 19:36
1  
Finally the problem is solved. I have just added the line: Defaults env_keep="DISPLAY XAUTHORITY" at the end of visudo. Thanks to all, specially @Thor for kind help. –  Apurba Aug 17 '12 at 8:03

2 Answers 2

up vote 7 down vote accepted

You need to allow the root user access to the X server:

xhost local:root

And point the command to the right DISPLAY:

sudo DISPLAY=$DISPLAY gedit /etc/profile
share|improve this answer
    
That solved the problem with opening gedit as sudo, but still can't lunch super-boot-manager. It is showing same error –  Apurba Aug 15 '12 at 5:44

Finally the problem is solved. I have just added the line:

Defaults env_keep="DISPLAY XAUTHORITY"

at the end of visudo.

To do that you have to run

sudo visudo

it will open the file then add the above line at the end.

Thanks to all, specially @Thor for kind help

share|improve this answer

Your Answer

 
discard

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.