Results 1 to 9 of 9

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

  1. #1

    Default 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:
    Code:
    # sudo gedit /usr/bin/deadbeef
    ..but every time I try, no matter the file, I get this error message:
    Code:
    (gedit: [process #] ): Gtk-WARNING **: cannot open display
    I already know:
    I can circumvent this by going:
    Code:
    # 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
    This has been happening since I first installed openSUSE, so I haven't screwed up anywhere in the process.

  2. #2
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    1,918

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

    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 :
    Code:
    gnomesu gedit /usr/bin/deadbeef
    Best regards,
    Greg
    Best regards,
    Greg

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,003

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

    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.
    Henk van Velden

  4. #4
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,673
    Blog Entries
    15

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

    Quote Originally Posted by misfisk
    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.

    # sudo gedit /usr/bin/deadbeef
    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


  5. #5

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

    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.

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,003

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

    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.
    Henk van Velden

  7. #7

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

    The display should be open for su and su -l sessions thanks to the optional pam_xauth module (which is commented out in sudo):
    Code:
    grep 'pam_xauth.so' /etc/pam.d/*  | awk -F ":" '{ printf "%s\t(%s)\n", $2, $1}'

  8. #8

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

    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

  9. #9
    Join Date
    Jun 2008
    Location
    Earth - Denmark
    Posts
    10,730

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

    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:

    Code:
    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!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •