I run XWindows on a CentOS 5.9 box as a non-root user. To perform administrative tasks, I occasionally log in as root using “su” in a terminal window. However, I found that I was unable to start any GUI applications as root. I got the following error:
Xlib: connection to ":0.0" refused by server Xlib: No protocol specified E233: cannot open display Xlib: connection to ":0.0" refused by server Xlib: No protocol specified
This can happen when xhost isn’t configured to allow local, non-network connections. As the user who started the xwindows session (not root) run:
$ xhost access control enabled, only authorized clients can connect INET:localhost.localdomain SI:localuser:cfinch
This shows that network connections to X are only allowed from localhost, and from a local user called cfinch (who started the X server). To fix the problem, run the following command to allow local user “root” to connect to the X server:
$ xhost local:root non-network local connections being added to access control list
To see what this did, run xhost without any arguments:
$ xhost access control enabled, only authorized clients can connect LOCAL: INET:localhost.localdomain SI:localuser:cfinch
Now root can run GUI applications, such as the system-config-* tools.
The same idea…
#!/bin/bash
xhost + local:
xhost + si:localuser:root
Added line to /etc/crontab…
@reboot /home/foo/Documents/root_xhost.sh