使用sudo运行应用程序时无法连接到X Server
当我使用sudo
命令运行某些软件时,它显示错误
cannot connect to X server
例如,如果我运行以下命令:
$ sudo gedit /etc/profile
我正在接受以下命令
(gedit:6758): WARNING **: Command line `dbus-launch --autolaunch=84b871d735f31ffe014dc9ba00000009 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed. Cannot open display: Run 'gedit --help' to see a full list of available command line options.
或者如果我正在运行super-boot-manager
我会收到以下错误
buc: cannot connect to X server
请帮忙。
您需要允许root用户访问X服务器:
xhost local:root
并将命令指向右侧DISPLAY
:
sudo DISPLAY=$DISPLAY gedit /etc/profile
最后问题解决了。 我刚添加了这一行:
默认值env_keep =“DISPLAY XAUTHORITY”
在visudo
结束时。
要做到这一点,你必须运行
sudo visudo
它将打开文件,然后在最后添加上面的行。
感谢所有人,特别是@Thor的亲切帮助