0

I get this wierd error when I run applications as root.

**(gedit:630): WARNING **: could not open X display
No protocol specified
Unable to init server

(gedit:630): Gtk-WARNING **: Cannot open display: :0.0

I'm using Arch Linux. I use su - to login as root. And this error comes when im running the X server. Also if i copy .Xauthority into the /root/ it works without error.

compiler
  • 361

2 Answers2

1

It is really unclear with your question's current state.

I believe you have to export the display.

export DISPLAY='IP:0.0'

See the answer here.

Check the server's sshd_config (normally /etc/ssh/sshd_config), and make sure the X11Forwarding option is enabled with the line

X11Forwarding yes

If X11Forwarding is not specified, the default is no.

Ramesh
  • 39,297
  • ok wait i dont have ssh/ folder. im using arch linux, i don't have openssh installed on my computer! – compiler Jul 04 '14 at 03:52
  • im actually trying this on a live-CD its a remastered iso. other thing after booting the iso. if i login to root run startx and logout then come back to normal user then it works great, this error doesn't come up. – compiler Jul 04 '14 at 03:58
  • 1
    @Chronix01 please add these details to your original question. We need to know exactly how you're running as root (sudo? su? Login as root?), we need to know your OS and distribution, and we need to know if you are logged in physically or remotely and if there is a running X server when you get that error. Also have a look at this answer. – terdon Jul 04 '14 at 08:53
0

Running su - erases almost all environment variables. GUI applications need two environment variables to know how to connect to the GUI environment: DISPLAY and XAUTHORITY. See Open a window on a remote X display (why "Cannot open display")? for a more detailed explanation. The command su - retains DISPLAY but not XAUTHORITY. So your GUI application knows where to connect, but doesn't have the requisite password (“cookie”).

Instead of logging in as root, just run the program without changing most environment variables: run su, not su -.

If you want to do complicated things, read Can I launch a graphical program on another user's desktop as root?