安装Linux后合上笔记本屏幕后如何实现不休眠,远程连接不断开?
想让笔记本电脑做为服务器,合上笔记本屏幕后如何让笔记本关闭屏幕,不休眠,远程连接不断开?
想要马儿跑,就需要给马儿吃草。同样,我们使用电脑,就需要给电脑供电,消耗电能。但电能也是需要消耗资源的,为了降低能源消耗,电脑支持多种形式的节能措施,包括合上笔记本电脑的屏幕,自动关闭屏幕。但是如果把笔记本作为服务器,期望长期开机运行,并能够远程连接,这时候就需要对电脑进行特殊的设置了。
在我们合上笔记本屏幕后,笔记本电脑会按照顺序执行下面的节能行为:
首先关闭屏幕,并锁定登录会话,断开远程连接会话;
其次在一段时间后,会执行休眠/睡眠行为,挂起计算机。
所以需要针对这两种情况进行设置。
- 设置关闭屏幕后不执行休眠
修改文件“/etc/systemd/logind.conf”中下面三个配置项:
HandleLidSwitch=lock
HandleLidSwitchDocked=ignore
LidSwitchIgnoreInhibited=yes
注意:去掉前面的#字符。
执行命令“systemctl restart systemd-logind”让配置项生效(或重启电脑)

- 禁止电脑运行一段时间后进入休眠/睡眠模式
在Linux中禁用挂起和休眠为了防止Linux系统挂起或进入休眠状态,需要执行如下命令。
1、查询当期状态
systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target

2、禁用休眠/睡眠行为
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

再次查看执行后的状态。

3、取消禁用行为
systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

好了,通过上面两个设置,就可以让笔记本一直处于运行状态了。