編輯下列文件:/etc/systemd/logind.conf
#HandlePowerKey按下電源鍵后的行為,默認power off
#HandleSleepKey 按下掛起鍵后的行為,默認suspend
#HandleHibernateKey按下休眠鍵后的行為,默認hibernate
#HandleLidSwitch合上筆記本蓋后的行為,默認suspend(改為lock;即合蓋不休眠)在原文件中,還要去掉前面的#
運行:systemctl restart systemd-logind 就會生效。
--------------------------------------------------------------------------------------------------
附上運行演示:
[root@ikensee]# vim /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 (在這里把#號去掉,然后把默認suspend改成lock)
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RemoveIPC=no
#UserTasksMax
[root@ikensee]# systemctl restart systemd-logind (運行重啟生效)