centos7使用gnome桌面不锁屏解决方法
0赞公司新服务器,安装的centos7系统以及gnome桌面服务。后续在vnc使用中,发现桌面不会锁屏。即使设置了锁屏时间,但是到了时间,也不会锁屏。
通过查阅各种方法,找到了临时解决方案。
centos7的gnome桌面安装时,不会自动安装gnome-screensaver。使用如下命令可以查看是否有安装:
rpm -qa | grep screensaver |
安装gnome-screensaver 包。使用yum命令即可安装
yum install -y gnome-screensaver |
安装完毕后,使用rpm命令查看
[root@xle02 ~]# rpm -qa | grep screensaver gnome-screensaver-3.6.1-20.el7.x86_64 |
安装之后,需要启动该服务。该服务,通过执行以下命令启动。
gnome-screensaver & |
这个命令,是要在每一个用户下,去执行的。这样,每一个用户才能够实现自动锁屏。有另外一个方法是,修改 /etc/X11/xinit/xinitrc 文件,该文件是每一个用户创建vnc时,就会执行的初始化文件。
修改如下:
. /etc/X11/xinit/xinitrc-common exec gnome-screensaver & # 增加这一行,启动gnome-screensaver
# The user may have their own clients they want to run. If they don't, # fall back to system defaults. if [ -f $HOME/.Xclients ]; then exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients || \ exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients elif [ -f /etc/X11/xinit/Xclients ]; then exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients || \ exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients else # Failsafe settings. Although we should never get here # (we provide fallbacks in Xclients as well) it can't hurt. [ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45' [ -x /usr/bin/xclock ] && /usr/bin/xclock -geometry 100x100-5+5 & [ -x /usr/bin/xterm ] && xterm -geometry 80x50-50+150 & [ -x /usr/bin/twm ] && /usr/bin/twm fi |
以上,就是解决centos7使用gnome桌面,不能锁屏的方案。如果是使用mate桌面系统,那么是可以锁屏的,所以推荐使用mate桌面系统。
另外,如果在centos7使用gnome桌面,想修改全局的锁屏配置,可以参考如下网站,进行设置:
https://www.thegeekdiary.com/how-to-customize-the-screensaver-options-in-gnome-on-centos-rhel-7/
主要就是在 /etc/dconf/db/local.d/ 目录下,创建00-screensaver文件,在文件里面写入指定内容,在/etc/dconf/db/local.d/locks 目录下,创建screensaver文件,在文件中写入指定内容。
如下所示:
|
然后指定 dconf update 命令,更新screensaver配置。此时就会将所有用户的锁屏配置给固定住,用户也就无法配置了。
通过查阅资料,得到以下信息:
In Gnome Shell 3.6 and earlier, the old gnome-screensaver program was present, and if GDM was not running, gnome-screensaver would be invoked - allowing you to lock the screen. Starting in Gnome Shell 3.8 (included in Fedora 19), gnome-screensaver support has been dropped completely. This was done for three reasons: reduced code complexity coupled with the fact that the screensaver is seen as an unneeded feature, and the fact that the eventual move to Wayland will require screensaver, locking, etc. support to be in the compositor. So the only Gnome-integrated way of locking the screen is to have GDM running, which will respond to a dbus message telling it to lock the screen. Other display managers (such as XDM) have not been designed to respond to this dbus message, and so the screen cannot be locked. |
意思是,在gnome3.6版本以前,使用gnome-screensaver,之后就不再使用这个了。而是使用GDM。
所以,需要执行如下命令,启动 gdm
systemctl start gdm |
然后锁屏功能也就正常了。
对于查看gnome版本:
在gnome3以前,使用 gnome-about --gnome-version
lujun@xl02 ~ $ gnome-about --gnome-version Version: 2.28.2 Distributor: CentOS Project Build Date: 10/10/2012 |
对于gnome3以后,使用 gnome-shell --version
[root@xle02 ~]# gnome-shell --version GNOME Shell 3.28.3 |