服务器进入睡眠状态后,很多服务不能远程连接使用,例如 SSH 会连接不上,需要修改一下配置
#禁止睡眠
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
#启用睡眠
systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
#配置盖子(笔记本)
vi /etc/systemd/logind.conf
找到该行#HandleLidSwitch=suspend,将该行更改为以下所需的设置之一:
#关闭盖子时关闭计算机
HandleLidSwitch=poweroff
#在合上盖子时到休眠计算机
HandleLidSwitch=hibernate
#关闭盖子时暂停计算机
HandleLidSwitch=suspend
#不执行任何操作
HandleLidSwitch=ignore
#保存文件,然后重新启动服务
systemctl restart systemd-logind
#或者
service systemd-logind restart