1、WSL 开启 systemd
- 在 WSL 里执行:
sudo tee /etc/wsl.conf >/dev/null <<'EOF'
[boot]
systemd=true
EOF
- 然后在 Windows PowerShell 执行:
wsl --shutdown
- 重新打开 Ubuntu 生效。
2、创建专用 SSH 密钥并免密登录 NAS
- 在 WSL 执行:
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_openclaw -C "openclaw-tunnel" -N ""
ssh-copy-id -p 22 -i ~/.ssh/id_ed25519_openclaw.pub demo@192.168.2.238
ssh -i ~/.ssh/id_ed25519_openclaw -p 22 demo@192.168.2.238 "echo OK"
- 看到
OK就说明成功。
- 在 NAS 执行:
chmod 755 ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown demo:users ~ ~/.ssh ~/.ssh/authorized_keys
sed -i 's/\r$//' ~/.ssh/authorized_keys
ls -ld ~ ~/.ssh ~/.ssh/authorized_keys
3、写入 OpenClaw token
- 在 WSL 执行:
mkdir -p ~/.openclaw
cat > ~/.openclaw/.env <<'EOF'
OPENCLAW_GATEWAY_TOKEN=demo-openclaw-2026
EOF
chmod 600 ~/.openclaw/.env
4、创建 SSH 隧道后台服务
- 在 WSL 执行:
sudo tee /etc/systemd/system/ocw-tunnel.service >/dev/null <<'EOF'
[Unit]
Description=OpenClaw SSH Tunnel to NAS
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=slobys
WorkingDirectory=/home/slobys
Environment=HOME=/home/slobys
ExecStart=/usr/bin/ssh -NT \
-i /home/slobys/.ssh/id_ed25519_openclaw \
-o IdentitiesOnly=yes \
-p 22 \
-o ExitOnForwardFailure=yes \
-o ServerAliveInterval=30 \
-o ServerAliveCountMax=3 \
-o StrictHostKeyChecking=accept-new \
-L 18790:127.0.0.1:18789 \
demo@192.168.2.238
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
5、创建 OpenClaw node 后台服务
- 在 WSL 执行:
sudo tee /etc/systemd/system/ocw-node.service >/dev/null <<'EOF'
[Unit]
Description=OpenClaw Node Host
After=network-online.target ocw-tunnel.service
Wants=network-online.target
Requires=ocw-tunnel.service
[Service]
Type=simple
User=slobys
WorkingDirectory=/home/slobys
Environment=HOME=/home/slobys
Environment=PATH=/home/slobys/.npm-global/bin:/usr/local/bin:/usr/bin:/bin
EnvironmentFile=/home/slobys/.openclaw/.env
ExecStart=/home/slobys/.npm-global/bin/openclaw node run --host 127.0.0.1 --port 18790 --display-name Win-PC
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
6、加载并启用服务
- 在 WSL 执行:
sudo systemctl daemon-reload
sudo systemctl enable --now ocw-tunnel.service
sudo systemctl enable --now ocw-node.service
7、本机检查
- 在 WSL 执行:
sudo systemctl status --no-pager ocw-tunnel.service
sudo systemctl status --no-pager ocw-node.service
ss -lntp | grep 18790 || echo "18790 FREE"
nc -z 127.0.0.1 18790 && echo TUNNEL_OK || echo TUNNEL_FAIL
- 正常时会看到:
openclaw-ssh-tunnel.service是active (running)openclaw-node.service是active (running)127.0.0.1:18790正在监听- 输出
TUNNEL_OK
8、NAS 端验证节点是否在线
- 在 NAS 执行:
openclaw devices list
openclaw nodes status
openclaw nodes describe --node "Win-PC"
- 你的当前正常结果应类似:
Win-PC出现在devices listKnown: 1 · Paired: 1 · Connected: 1Status: paired · connected
9、测试远程执行
- 在 NAS 上先放行一个命令:
openclaw approvals allowlist add --node "Win-PC" "/usr/bin/uname"
- 然后测试:
openclaw nodes run --node "Win-PC" -- /usr/bin/uname -a
- 如果能返回 Linux/WSL 系统信息,就说明整套已经跑通。
10、一键启动
- 设置成批处理:start-ocw.bat
@echo off
start "" /min wsl.exe -d Ubuntu -u root -- bash -lc "systemctl start ocw-tunnel.service; systemctl start ocw-node.service; exec tail -f /dev/null"
exit
11、一键清理
- 在 WSL / Ubuntu 里创建脚本:
cat > ~/reset-openclaw-node-soft.sh <<'EOF'
#!/usr/bin/env bash
set -e
echo "=== [1/10] 停止系统级服务 ==="
sudo systemctl stop ocw-node.service 2>/dev/null || true
sudo systemctl stop ocw-tunnel.service 2>/dev/null || true
sudo systemctl disable ocw-node.service 2>/dev/null || true
sudo systemctl disable ocw-tunnel.service 2>/dev/null || true
echo "=== [2/10] 停止用户级残留服务 ==="
systemctl --user stop openclaw-node.service 2>/dev/null || true
systemctl --user stop openclaw-ssh-tunnel.service 2>/dev/null || true
systemctl --user disable openclaw-node.service 2>/dev/null || true
systemctl --user disable openclaw-ssh-tunnel.service 2>/dev/null || true
echo "=== [3/10] 杀掉残留进程 ==="
pkill -f 'ssh -NT .*18790:127\.0\.0\.1:18789' 2>/dev/null || true
pkill -f 'openclaw node run --host 127.0.0.1 --port 18790' 2>/dev/null || true
echo "=== [4/10] 删除 systemd 服务文件 ==="
sudo rm -f /etc/systemd/system/ocw-node.service
sudo rm -f /etc/systemd/system/ocw-tunnel.service
rm -f ~/.config/systemd/user/openclaw-node.service
rm -f ~/.config/systemd/user/openclaw-ssh-tunnel.service
echo "=== [5/10] 刷新 systemd ==="
sudo systemctl daemon-reload || true
sudo systemctl reset-failed || true
systemctl --user daemon-reload 2>/dev/null || true
systemctl --user reset-failed 2>/dev/null || true
echo "=== [6/10] 删除 node 本地状态 ==="
rm -f ~/.openclaw/node.json
rm -f ~/.openclaw/exec-approvals.json
rm -f ~/.openclaw/exec-approvals.sock
echo "=== [7/10] 可选保留 token;默认删除 .env 方便完全重来 ==="
rm -f ~/.openclaw/.env
echo "=== [8/10] 检查端口 18790 是否释放 ==="
sleep 2
if ss -lntp | grep -q 18790; then
echo "警告:18790 仍被占用"
ss -lntp | grep 18790 || true
else
echo "18790 FREE"
fi
echo "=== [9/10] 保留以下内容不删 ==="
echo "- OpenClaw CLI 本体"
echo "- ~/.ssh/id_ed25519_openclaw"
echo "- WSL/Ubuntu 环境"
echo "=== [10/10] 完成:当前节点侧已清零,可重新部署 ==="
EOF
chmod +x ~/reset-openclaw-node-soft.sh
~/reset-openclaw-node-soft.sh
- 在 NAS 删除旧
Win-PC记录:
openclaw devices list
openclaw devices remove <旧ID>










