Using gedit as root: "Gtk-WARNING **: cannot open display:"

I’ve been searching for a permanent solution for some time now, but the threads containing the same error message never seem to be about the same issue.

I want to:
I’m not trying anything fancy, all I want to do is open a write-protected file with gedit as root, like so:


# sudo gedit /usr/bin/deadbeef

…but every time I try, no matter the file, I get this error message:


(gedit: [process #] ): Gtk-WARNING **: cannot open display

I already know:
I can circumvent this by going:


# xhost +local:root
# sudo su
# export DISPLAY=:0.0

…or something along those lines

Help!
I have no idea why this is necessary, it’s stupidly inconvenient to say the least :slight_smile:
This has been happening since I first installed openSUSE, so I haven’t screwed up anywhere in the process.

Hi You should use gnomesu instead of sudo for running graphical gnome apps in root mode. For KDE it’s kdesu so running gedit like this will most likely be successful :

gnomesu gedit /usr/bin/deadbeef

Best regards,
Greg

It is a normal security issue. You have a multi user system where many users can login, either local or remote, in a GUI session. What if other loged iin people would be able to open windows on your desktop without your allowance? Inconvenient at least, but the would also be able to create a window such that thay could read all your keyboard typing including your bank accounts. Thus the need for giving allowance with xhost.

On the other hand, the CLI session root uses does not know which of the displays it should open the window. Again there can be many, local and remote. Thus the need for setting the DISPLAY environment variable.

But using gnomesu from your normal user GUI this will be handled for you (at least kdesu does)…

Hehe, glistwan was quicker, but I have more explanation.

Hi
Use gnomesu or xdg-su commands instead.


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.27-0.2-default
up 4 days 23:28, 3 users, load average: 0.79, 1.16, 0.54
GPU GeForce 8600 GTS Silent - Driver Version: 260.19.29

Thank you very much for the fast replies.

I’m still a little new in openSUSE, Ubuntu has been my OS for the last couple of years.
gnomesu solved the problem, I don’t know why I haven’t come across that solution before now.

Well, this security mechanism existed in X way before Linux existed. Thus it must be available in Ubuntu also. But maybe the defaults are different there.

The display should be open for su and su -l sessions thanks to the optional pam_xauth module (which is commented out in sudo):


grep 'pam_xauth.so' /etc/pam.d/*  | awk -F ":" '{ printf "%s	(%s)
", $2, $1}'

Greg,
I tried ~> gnomesu gedit /etc/sysctl.conf as a user
I am getting error as:
No protocol specified
(gnomesu:3218):WARNING: Could not open X display

How I can open /etc/sysctl.conf for editing. Pl. help

On 05/10/2013 10:16 AM, susprusty wrote:
>
> Greg,

Greg wrote what he wrote in this thread over two years ago!

> I tried ~> gnomesu gedit /etc/sysctl.conf as a user
> I am getting error as:
> No protocol specified
> (gnomesu:3218):WARNING: Could not open X display
>
> How I can open /etc/sysctl.conf for editing. Pl. help

because what you wrote should just work tell us more about your
situation:

  • operating system and version in use

  • desktop environment (if applicable) in use

  • VM (if applicable) in use

  • if you are typing on one machine and wanting to edit the
    sysctl.conf file on a different machine:
    – what OS and version on your machine and the distant machine
    – what tools, protocols, etc are you using to connect to the other
    machine

please next time do not tell us a story, instead copy and paste the
full input and output of the command line…from the first prompt
through the entire operation and the next empty prompt, like:


denverd@linux-os114:~> gnomesu gedit /etc/sysctl.conf
denverd@linux-os114:~>

of course, in your case i expect to see the error…and maybe a # or
two.


dd
openSUSE®, the “German Engineered Automobile” of operating systems!