解决Centos 7 VNC黑屏

时间:2025-05-06 08:31:40

在配置Centos 7下VNC时发现root用户可以正常登陆VNC桌面,而普通用户VNC桌面黑屏,分析~/.vnc/xstarup 后发现是普通用户没有执行/etc/X11/xinit/xinitrc的权限

#!/bin/sh

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/etc/X11/xinit/xinitrc
# Assume either Gnome or KDE will be started by default when installed
# We want to kill the session automatically in this case when user logs out. In case you modify
# /etc/X11/xinit/Xclients or ~/.Xclients yourself to achieve a different result, then you should
# be responsible to modify below code to avoid that your session will be automatically killed
if [ -e /usr/bin/gnome-session -o -e /usr/bin/startkde ]; then
    vncserver -kill $DISPLAY
fi

root权限依次执行以下命令,给其他用户对此文件的读和执行权限

#chmod 755 /etc/X11/xinit/xinitrc
#chmod 755 /etc/X11/xinit/xinitrc-common

这时用普通用户权限执行 /etc/X11/xinit/xinitrc,出现以下错误

yala@A-boat:~$ /etc/X11/xinit/xinitrc
xrdb: Can't open display ''
xmodmap:  unable to open display ''

(process:1367): dconf-CRITICAL **: 10:39:23.653: unable to create file '/run/user/1001/dconf/user': 权限不够.  dconf will not work properly.

(process:1367): dconf-CRITICAL **: 10:39:23.654: unable to create file '/run/user/1001/dconf/user': 权限不够.  dconf will not work properly.

我们把对应文件chown下

chown yala:yala  /run/user/1001/dconf -R