当前位置: 首页 > news >正文

如何防止 Linux Ubuntu 笔记本电脑合盖时屏幕关闭导致系统挂起/休眠 All In One

如何防止 Linux Ubuntu 笔记本电脑合盖时屏幕关闭导致系统挂起/休眠 All In One

Ubuntu 22.04.5 LTS 电源管理

image

questions

场景:Mac 通过 SSH 远程访问 Ubuntu 部署的 OpenClaw 服务, 由于笔记本屏幕合盖后会导致系统进入休眠状态,导致 SSH 链接中断 ❌

xgqfms@ai2026:~$ client_loop: ssh_packet_write_poll: Connection to 192.168.124.25 port 22: Host is down

image

image

solution

修改 Linux 系统登录配置文件 /etc/systemd/logind.conf

  1. sudo 进入文件编辑
# VIM (i, esc, :wq)
$ sudo vim /etc/systemd/logind.conf
# or
$ sudo nano /etc/systemd/logind.conf# vscode + root passowrd
$ code /etc/systemd/logind.conf
  1. 去掉以下几个字段的注释符号 #, suspend / hibernate 改成 ignore

suspend ❌

[Login]#HandleLidSwitch=suspend
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore

ignore ✅

[Login]HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

HandleLidSwitch:合盖时
ExternalPower:插电源时
Docked:接外接显示器

  1. 查看
$ 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-analyze 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
#HandleSuspendKey=ignore
#HandleHibernateKey=ignore
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
#HandleRebootKey=reboot
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodesMax=400k
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192
  1. 验证
  1. 重启系统
$ sudo reboot
# ⚠️ 如果不是无 GUI 的服务器版 Ubuntu,千万不要使用这个命令,会导致重新登录后出现黑屏问题 ⚠️ 
$ sudo systemctl restart systemd-logind

image

image

demos

使用 mac SSH 远程访问 OpenClaw

  1. ssh server
# ubuntu
$ sudo apt update
$ sudo apt install openssh-server -y# 启动 SSH
$ sudo systemctl start ssh
# 查看 SSH 状态
$ sudo systemctl status ssh# 设置开机自动启动服务
$ sudo systemctl enable ssh
$ sudo reboot
$ sudo systemctl status ssh
[sudo] password for xgqfms: 
Sorry, try again.
[sudo] password for xgqfms: 
● ssh.service - OpenBSD Secure Shell serverLoaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)Active: active (running) since Fri 2026-03-13 17:10:08 CST; 2 days agoDocs: man:sshd(8)man:sshd_config(5)Main PID: 792 (sshd)Tasks: 1 (limit: 9235)Memory: 6.5MCPU: 326msCGroup: /system.slice/ssh.service└─792 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"3月 13 17:10:08 ai2026 systemd[1]: Starting OpenBSD Secure Shell server...
3月 13 17:10:08 ai2026 sshd[792]: Server listening on 0.0.0.0 port 22.
3月 13 17:10:08 ai2026 sshd[792]: Server listening on :: port 22.
3月 13 17:10:08 ai2026 systemd[1]: Started OpenBSD Secure Shell server.
3月 13 17:13:24 ai2026 sshd[4580]: pam_unix(sshd:auth): authentication failure; logname= ui>
3月 13 17:13:26 ai2026 sshd[4580]: Failed password for xgqfms from 192.168.124.23 port 5650>
3月 13 17:13:33 ai2026 sshd[4580]: Accepted password for xgqfms from 192.168.124.23 port 56>
3月 13 17:13:33 ai2026 sshd[4580]: pam_unix(sshd:session): session opened for user xgqfms(u>
3月 15 16:11:07 ai2026 sshd[20968]: Accepted password for xgqfms from 192.168.124.23 port 5>
3月 15 16:11:07 ai2026 sshd[20968]: pam_unix(sshd:session): session opened for user xgqfms(>
  1. ssh client
# mac
$ ssh username@ip_address
# paasword

image

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


http://www.jsqmd.com/news/481849/

相关文章:

  • AgentAi视频模型开发对接部署使用
  • 大模型使用中遇到的坑——HTTP query 参数探讨 - liyan
  • 全国老酒名酒回收行业科普:京城亚南酒业凭硬核实力领跑行业榜单 - 品牌排行榜单
  • 2026.3.14总结
  • mysql注入
  • 折腾笔记[46]-在安卓手机运行基于java8的lua解释器
  • 快递成本对比程序,输入重量目的地,对比多家快递价格,选最省钱,时效合适的
  • 喷水织机卷取机构设计(SolidWorks+CAD)
  • Redux - redux-saga 中fork作用详解
  • 高并发40问学习笔记
  • 通达信【反弹低吸寻机】副图与反弹低吸寻机指标公式CJM99分享源码
  • 2026六大城市高端腕表“隐形故障”大数据:北京爱彼摆轮游丝、上海江诗丹顿表盘氧化、杭州宝玑月相调校避坑指南 - 时光修表匠
  • 收藏!使用Python读写Excel大数据文件的3种有效方式
  • XlsxWriter,一款强大的Python Excel处理库
  • HTTP 协议 qeury 参数的说明 - liyan
  • 2026年度北京上门回收老酒名酒正规机构官方测评排行 - 品牌排行榜单
  • 盘式电机:电动车驱动的未来之星
  • 基于时间约束的CAN网络管理一致性测试方法复现与实现
  • 2026年2月,探寻受欢迎的成都火锅品牌都有谁,附近火锅/火锅/牛肉火锅/美食/地摊火锅/社区火锅,成都火锅品牌排行 - 品牌推荐师
  • 2026六大城市高端腕表维修“二次损伤”调查报告:北京上海百达翡丽、南京杭州欧米茄养护避坑全解析 - 时光修表匠
  • DigVPS 测评 - 新增商户 HostBlazer 并奉上 US Central - Dallas 产品详评数据,性能不错,适合建站,九折出售中。
  • 北京名酒老酒上门回收实测:4家靠谱商家测评排名,藏家变现不踩坑 - 品牌排行榜单
  • 3-sum 问题 - liyan
  • emacs! start org-mode! --org-mode使用备注 - liyan
  • python调试方法(其一) - liyan
  • CLI-Anything + Gear 最佳实践与踩坑修复沉淀
  • ratelimit服务流量限制 - liyan
  • 北京卡地亚维修、深圳爱彼保养、杭州万国检修|6城高端腕表维修科普指南 - 时光修表匠
  • windows用户有哪些必备的小工具软件能大幅提高效率而且占用资源低?
  • web中各个标签的关系