微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🛡️

OpenClaw 服务器安全加固专家

Host Hardening · v1.0.5
专业技能 安全 B 级 作者 ppiankov 公开目录收录
下载 1.4k 安装 0 收藏 3.9k 浏览 5
原始页面

简介

为 OpenClaw 网关服务器提供 SSH 密钥认证、防火墙、入侵防护等一站式安全加固方案,需 root 权限执行

原始描述

Harden an OpenClaw Linux server with SSH key-only auth, UFW firewall, fail2ban brute-force protection, and credential permissions. Use when setting up a new...

中文使用说明 来自收录源

核心用法

本技能针对运行 OpenClaw 的 Linux 服务器(Ubuntu/Debian)提供系统级安全加固,涵盖四大核心模块:

1. SSH 密钥专属认证 通过修改 /etc/ssh/sshd_config 禁用密码登录,强制仅允许密钥认证,从根本上杜绝暴力破解风险。操作前必须验证密钥登录可用,否则将导致服务器锁死。

2. UFW 防火墙最小化暴露 默认拒绝所有入站流量,仅开放 SSH 端口,遵循最小权限原则。支持按需扩展(如 HTTPS 443 端口)。

3. Fail2ban 动态防护 自动安装并启用 fail2ban 服务,对 SSH 暴力破解行为实施 IP 封禁,形成第二层防御。

4. 凭证与服务加固

  • 设置 OpenClaw 凭证目录权限为 700(仅所有者可读写执行)
  • 可选创建 systemd 服务实现网关自启动,确保故障自动恢复

显著优点

  • 纵深防御架构:SSH 密钥 + UFW 网络隔离 + Fail2ban 行为检测三层防护
  • OpenClaw 场景优化:专门针对 OpenClaw 网关服务设计,包含凭证权限与服务持久化
  • 生产级可靠性:systemd 服务配置包含自动重启策略(Restart=always)
  • 操作可逆性强:所有配置均通过标准系统文件修改,便于审计与回滚

潜在局限与风险

  • 单点失效风险:SSH 密钥丢失或损坏将导致完全无法登录,需预先配置备用访问通道
  • 网络锁定陷阱:若云服务商安全组未同步开放 SSH 端口,UFW 启用后将阻断连接
  • Root 依赖过重:大量操作需 root 权限,存在误操作导致系统不稳定的风险
  • 发行版局限:包管理命令针对 apt(Debian/Ubuntu),其他发行版需手动适配
  • 服务运行权限:OpenClaw 网关默认以 root 运行,存在潜在权限过大问题

适合人群

  • DevOps 工程师:需要快速标准化新服务器安全基线
  • 系统管理员:负责 OpenClaw 生产环境部署与运维
  • 安全审计人员:进行服务器合规性检查或入侵后加固
  • 技术型开发者:具备 Linux 基础,能理解 SSH/防火墙配置逻辑

常规风险管控

  • 强制预检机制:技能明确要求在禁用密码前验证密钥登录
  • 交互式确认:文档规定每阶段需用户显式批准,禁止自动执行
  • 验证清单:提供 5 项命令式验证步骤,确保每项配置生效
  • 服务名特殊说明:特别标注 Ubuntu SSH 服务名为 ssh 而非 sshd,避免常见踩坑

技能正文


name: host-hardening description: Harden an OpenClaw Linux server with SSH key-only auth, UFW firewall, fail2ban brute-force protection, and credential permissions. Use when setting up a new OpenClaw instance, auditing server security, or after a security incident. Requires root/sudo on Linux (Ubuntu/Debian).

Host Hardening

Secure a Linux server running OpenClaw.

Requirements

  • OS: Linux (Ubuntu/Debian — adjust package commands for other distros)
  • Privileges: Root or sudo required — this skill modifies system-wide security config
  • Pre-check: Verify you have SSH key-based access before disabling password auth

⚠️ All commands below modify system configuration. Confirm with the user before running each section. Do not run these automatically without explicit approval.

SSH — Key-Only Auth

Disables password authentication. Ensure key-based SSH works first or you will be locked out.

sed -i 's/^#*PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart ssh

Firewall — Deny All Except SSH

ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
yes | ufw enable

Add more rules as needed (e.g. ufw allow 443 for HTTPS).

Fail2ban — Brute-Force Protection

Installs fail2ban via apt (Debian/Ubuntu). Adjust for other package managers.

apt-get install -y fail2ban
systemctl enable --now fail2ban

Default config protects SSH. For custom jails: /etc/fail2ban/jail.local.

OpenClaw Credentials

chmod 700 ~/.openclaw/credentials

OpenClaw Gateway Service (optional)

Creates a systemd service for auto-restart on reboot. Runs as root — review the service file before enabling.

cat > /etc/systemd/system/openclaw-gateway.service << 'EOF'
[Unit]
Description=OpenClaw Gateway
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/env openclaw gateway
Restart=always
RestartSec=5
User=root
WorkingDirectory=/root/.openclaw
Environment=HOME=/root
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable openclaw-gateway

Verify

ufw status                                    # active, SSH allowed
systemctl is-active fail2ban                  # active
grep PasswordAuthentication /etc/ssh/sshd_config  # no
stat -c %a ~/.openclaw/credentials            # 700
systemctl is-enabled openclaw-gateway         # enabled

Lessons

  • On Ubuntu, SSH service is ssh not sshd
  • AWS security groups provide network-level filtering but UFW is defense-in-depth
  • Always verify key-based SSH access before disabling password auth
  • The gateway service is optional — only needed if OpenClaw should survive reboots

Host Hardening v1.0 Author: ppiankov Copyright © 2026 ppiankov Canonical source: https://clawhub.com/skills/host-hardening License: MIT

This tool follows the Agent-Native CLI Convention. Validate with: clawhub install ancc && ancc validate .

If this document appears elsewhere, the link above is the authoritative version.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

其他来源收录

同一技能在不同目录的原始页面:

标签

securitysshfirewalllinuxserver-administrationopenclawinfrastructuresystemdfail2banufw

同类 Skill