ssh后提权
ssh登录后,输入 sudo -i ,然后输入登录密码

查看电源设置
root@good-home:~# cat /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. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the logind.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-**yze cat-config systemd/logind.conf' to display the full config.
#
# See logind.conf(5) for details.
[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
#HandlePowerKey=poweroff
#HandlePowerKeyLongPress=ignore
#HandleRebootKey=reboot
#HandleRebootKeyLongPress=poweroff
#HandleSuspendKey=suspend
#HandleSuspendKeyLongPress=hibernate
#HandleHibernateKey=hibernate
#HandleHibernateKeyLongPress=ignore
#HandleLidSwitch=lock
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodesMax=
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192
#StopIdleSessionSec=infinity
root@good-home:~#
Handle 开头的
#HandlePowerKey=poweroff # 按下电源键后如何
#HandleSuspendKey=suspend # 待机挂起后如何
#HandleHibernateKey=hibernate # 按下休眠键后如何
#HandleLidSwitch=suspend # 合上笔记本盖后如何
#HandleLidSwitchDocked=ignore # 合上笔记本盖后外接显示器如何
可选的参数值
参数 |
说明 |
ignore |
忽略,啥也不干 |
power off |
关电源 |
reboot |
重启 |
halt |
挂起。停止所有的 CPU 功能,但是仍然保持通电。 |
suspend |
待机 |
hibernate |
进入休眠(内存数据存入硬盘,关闭电源) |
hybrid-sleep |
混合睡眠=睡眠+休眠,主要是为台式机设计的,内存和CPU还是活的。 |
lock |
锁屏,机器继续跑(相当于Win+L) |
其他选项
#LidSwitchIgnoreInhibited=yes # 合上笔记本盖子时是否应该忽略被某些应用程序所发出的“禁止休眠”的请求
- 当设置为
yes 时,无论如何都执行 HandleLidSwitch 的定义,即无论应用程序发出任何关于系统状态控制请求,都不会被执行,而是以 HandleLidSwitch 为准。
- 当设置为
no 时,不受 HandleLidSwitch 约束。即如果有应用程序发出请求,要求在合盖时不进行休眠或其他操作,系统将不会执行 HandleLidSwitch 定义的行为。
修改配置
保存时要用 :wq
vim /etc/systemd/logind.conf
# 修改
HandleLidSwitch=lock
LidSwitchIgnoreInhibited=yes
注意: 我这边只需要合上笔记本盖后不休眠,请根据自己情况选择参数。
改完 cat 查看一下,确保无误。
root@good-home:~# cat /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. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the logind.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-**yze cat-config systemd/logind.conf' to display the full config.
#
# See logind.conf(5) for details.
[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
#HandlePowerKey=poweroff
#HandlePowerKeyLongPress=ignore
#HandleRebootKey=reboot
#HandleRebootKeyLongPress=poweroff
#HandleSuspendKey=suspend
#HandleSuspendKeyLongPress=hibernate
#HandleHibernateKey=hibernate
#HandleHibernateKeyLongPress=ignore
HandleLidSwitch=lock
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
LidSwitchIgnoreInhibited=yes
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodesMax=
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192
#StopIdleSessionSec=infinity
重启服务, 使设置生效
systemctl restart systemd-logind
|