Why can't I run GUI apps from 'root': "No protocol specified"?
I installed debian onto my machine last night. Now, I don't understand why I can't run GUI apps from a terminal when running as root.
sudo -i glxgears
Generates the following output:
No protocol specified Error: couldn't open display :0
But when I first open the terminal I can run
glxgearsfrom the user account. Its only after I do
sudo -ithat the problem crops up. This happens for any GUI app that I try to run. I think its probably related to X11, but I'm not sure.
About Wayland, just in case: Arch Wiki, "sudo with graphical apps doesn't work on wayland ".
Accessing the X server requires two things:
$DISPLAYvariable pointing to the correct display (usually
- Proper authentication information
The authentication information can be explicitly specified via
$XAUTHORITY, and defaults to
$XAUTHORITYis set for your user,
sudowill set them for the new shell, too, and everything should work fine.
If they are not set, they will probably default to the wrong values and you cannot start and X applications.
$XAUTHORITYis usually not set explicitly. Just add
.bashrcor explicitly say
XAUTHORITY=~/.Xauthority sudo ...and everything should work.
You can also use
xauth listto check whether proper authentication information are available.
Be aware that `xhost +` completely deactivates authentication and allows everyone to access all application on your screen...
for debian, do I type the XAUTHORITY export as root? because it's not working on deb10? I login with sudo su