编辑下列文件:
[root@BiJiBen ~]# vi /etc/systemd/logind.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See logind.conf(5) for details.
[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
HandleLidSwitch=lock
很多地方看的是system!!到处抄;这里是Centos7.2!在systemd目录!!!
#HandlePowerKey按下电源键后的行为,默认power off
#HandleSleepKey 按下挂起键后的行为,默认suspend
#HandleHibernateKey 按下休眠键后的行为,默认hibernate
#HandleLidSwitch 合上笔记本盖后的行为,默认suspend (改为lock;即合盖不休眠)在原文件中,还要去掉前面的#
运行:
#systemctl restart systemd-logind
生效。