| name | linux-server |
| description | Operate Linux servers over SSH: Debian/Ubuntu systemd setup and maintenance, distro-aware health and intrusion audits, SSH, firewall and container exposure, swap, and proxy/VPN setup or tuning including Snell repair. Use for unclear or possibly compromised hosts as well as known hosts. Not for macOS network problems; Snell evidence-only audits belong to surge, and the REALITY+HY2 stack belongs to sing-box-reality-hy2. |
| metadata | {"version":"6"} |
Linux Server
主机角色和任务模式决定读什么证据、允许改什么状态。只在会改变这些决定时做分类。
保命规则
- 默认只读。用户明确要求配置、部署、修复或应用已知变更时才写。
- 改 SSH、防火墙或网络之前,保住当前 SSH 会话。有凭据和网络路径就开第二条活会话,没有就先安排好回滚,再动手。
- 验证 runtime 状态,不只看配置文件:
sshd -T、ss -tulpen、ufw status verbose、nft list ruleset、iptables -S、systemctl is-active。
- 多领域请求按可达性排优先级:先 SSH 可达,再防火墙可达,然后才是包、服务和调优。单领域请求就待在请求的领域里,不顺手加固。
- 补丁只在当前发行版大版本内打,跨大版本升级要用户明示。
- 覆盖配置写进专用目录:SSH 用
/etc/ssh/sshd_config.d/,sysctl 用 /etc/sysctl.d/,fail2ban 用 jail.local,systemd 用 unit drop-in。只有服务没有覆盖机制时才改包管理的默认文件。
首招:只读体检
没有更窄的命令集时从这里开始:
whoami && id && hostname && date -Is && uptime && uname -a
df -h / /var /boot 2>/dev/null || df -h
free -h
if command -v systemctl >/dev/null 2>&1; then systemctl --failed --no-pager; fi
ss -tulpen
if command -v sshd >/dev/null 2>&1; then
sshd -T | awk '$1 ~ /^(port|listenaddress|permitrootlogin|passwordauthentication|kbdinteractiveauthentication|pubkeyauthentication|maxauthtries|maxsessions|logingracetime|allowusers|allowgroups|authenticationmethods|permituserrc|x11forwarding)$/ { print }'
fi
if command -v ufw >/dev/null 2>&1; then ufw status verbose; fi
if command -v nft >/dev/null 2>&1; then nft list ruleset 2>/dev/null; fi
iptables -S 2>/dev/null
ip6tables -S 2>/dev/null
主机角色
任务模式
Debian/Ubuntu 之外,先读 /etc/os-release、init system、package manager 和实际 service 名。没有对应写入配方时停在只读取证并报告 coverage gap,不把 apt、UFW 或 ssh.service 命令硬套到其他发行版。
改文件五步
- 先定义回滚。需要文件副本时沿用原权限或收紧为 root-only,保留到语法、runtime 和必要的重启验证完成后删除。长期恢复交给备份系统,不在
/etc 堆积无期限的 .bak。
- 能验证就先验证语法:
sshd -t、nft -c -f、systemd-analyze verify。systemd-analyze verify 可能打印 Unknown key ... ignoring 后仍退出 0;目标 unit 的 warning 就不算通过,不能只看退出码。
- 服务支持 reload 且语法通过时,用 reload 不用 restart。
- SSH 或防火墙变更后,开一条全新连接确认可达。
- 重读 runtime 状态,报告实际生效的设置。
systemd drop-in 的 section 按 directive 归属拆分,不要因为都在同一文件就全写进 [Service]。例如 StartLimitIntervalSec=、StartLimitBurst= 属于 [Unit],Restart=、RestartSec= 属于 [Service]。daemon-reload 后用真实 runtime property 验收:systemctl show <unit> -p Restart -p RestartUSec -p StartLimitIntervalUSec -p StartLimitBurst。注意 RestartSec= 对应 RestartUSec,StartLimitIntervalSec= 对应 StartLimitIntervalUSec;文件内容和 verifier 退出 0 都不能替代 runtime 证据。