Find the answer to your Linux question:
Results 1 to 9 of 9
I have this problem with using X when I'm running linux as root. I normally login as a normal user then use 'su' to change to the root user. Once ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    using X as root


    I have this problem with using X when I'm running linux as root. I normally login as a normal user then use 'su' to change to the root user. Once I try to use X, I get the following error.
    Code:
    Xlib: connection to ":0.0" refused by the server
    Xlib: Cannot connect X to Server
    Check the DISPLAY environment or use `-d'.
    Also use the `xhost' program to verify that it is set to permit connections from your machine.
    Any ideas?
    The best things in life are free.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    How do you mean? You're logged in to X as a normal user, then su in a shell, and try to run an X program, is that right?
    In that case, it's a rather strange error. It would be far more understandable if it said something like no protocol specified, which would mean that you had no xauth for root.
    I've never seen this with local connections before. I would strace it.

  3. #3
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    Dolda,

    Yes, I log in as a normal user, change to root and when I try to open something like emacs, the error message appears. It's funny you say that you've never had this problem since I have been having this problem in Redhat and Debian. The error message is exactly the same in both distros. As for strace, do I just run it right after this error message appears?
    The best things in life are free.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    No, if you want to strace emacs, for example, you just run "strace emacs". strace gives you a list of all syscalls used by emacs, so I'd check for the one where Xlib connect()s to the X server.

  6. #5
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    strace

    After running 'strace emacs', the only lines that deal with Xlib states that the client (in this case, the root user) is not allowed to connect to ":0.0" This error starts from the read() along with two write() calls.
    The best things in life are free.

  7. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Try setting your XAUTHORITY env var to the path of the user's .Xauthority file.

  8. #7
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    solved

    Dolda,

    Thanks man, that took care of the problem. Just out of curiosity, would you mind explaining the theory behind this?
    The best things in life are free.

  9. #8
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319

    emacs

    I really hate posting things time after time but I've got no choice. BTW, I copied my normal user's .Xauthority over to root. Seems like that works too.
    O.K, so using X as root has been taken care of. Now I can launch anything that I want without seeing that nasty message. However, I've encountered another weird problem. If I use 'emacs -nw <file>', the rest of the emacs session (as long as konsole stays open) now will open with the '-nw' option even if I don't specify it.
    The best things in life are free.

  10. #9
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The .Xauthority file is simply used as a means of keeping intruders from your X server.
    Normally, the X server starts as an "open" server, in that anyone can connect to it. The servers started under gdm (or xdm, for that part), are told to use a authorization file (which you can create and manage yourself with the xauth command), so that only programs which can prove to also have access to the information in that file can use the X server. Pretty practical if you're connected to the internet so that not just anyone can open windows on your display.
    I don't know exactly how the X authorization scheme works, but the .Xauthority file probably holds some cryptocraphic info (I've seen common references to MIT-MAGIC-COOKIE, but I have no insight currently as to what it means) that the X server can use to challenge the client's Xlib.
    The strange thing is that usually, there is a pam_xauth module that automatically copies the relevant cookies from your .Xauthority when you use su. Maybe you just don't have it installed.
    To allow anyone to connect to your X server, see the "xhost" command.

Posting Permissions

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