WSL 安裝 openclaw (非root)

以下主要解決 非root user 進行安裝 opencalw.

以下內容範例設定: 需變更為你電腦的內容

* <WIN_BAT_PATH>: 開機時需要執行的 .bat 檔案; 如: E:\WSL\ubuntu\scripts\update_wsl_ports_by_admin.bat
* <WIN_IP>: windows IP

---

## 安裝 opcnelaw

* 步驟(在 WSL 終端機執行):

```bash
cd ~/
# install openclaw (and install nodejs)
curl -fsSL https://openclaw.ai/install-cli.sh | bash
# add openclaw into PATH
echo 'export PATH="$HOME/.openclaw/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# confirm openclaw version
openclaw --version
# setup and install daemon
openclaw onboard --install-daemon
# (略) openclaw設定, 自行上網或詢問 chatgpt/gemini, 不再贅述
```

* default website `http://localhost:18789`

## wsl啟動時openclaw就執行

* install daemon

```bash
# setup and install daemon
openclaw onboard --install-daemon
# start openclaw when booting
loginctl enable-linger $USER
```

## 內網(LAN)可以存取

```bash
openclaw config set gateway.bind lan
openclaw config set gateway.controlUi.allowInsecure true
openclaw config set gateway.controlUi.dangerouslyDisableDeviceAuth true
# 加入 Windows 的 IP(最重要)[<WIN_IP> 要修改為你的windows ip]
openclaw config set gateway.controlUi.allowedOrigins '["http://<WIN_IP>:18789", "http://localhost:18789", "http://127.0.0.1:18789"]'
# 重啟 Gateway
openclaw gateway restart
```

## 內網連線與防火牆轉發

這是讓其他電腦能透過你的 Windows IP (<WIN_IP>) 連進 WSL 的關鍵。

### 1. 開啟防火牆 (PowerShell 管理員權限) - 執行一次就好!

```powershell
New-NetFirewallRule -DisplayName "WSL SSH Port 18789" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 18789
```

### 2. 建立自動更新 [wsl to windows] Port Forwarding 的批次檔(解決 WSL IP 會變動的問題)

在 Windows (<WIN_BAT_PATH> 如 E:\WSL\ubuntu\scripts\update_wsl_ports_by_admin.bat) 最後加入
[可參考 "WSL 開機啟動並持續運行 (透過背景運行SSH)" ]

```bat
echo ====== 處理 openclaw dashboard web 18789
:: 刪除舊的 portproxy(忽略錯誤)-> 新增 port forwarding(監聽 Windows 所有介面,轉發到 WSL)
netsh interface portproxy delete v4tov4 listenport=18789 >nul 2>&1
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=18789 connectaddress=%WSL_IP% connectport=18789
if %errorlevel% equ 0 (
   :: <WIN_IP> 要修改為你的windows ip
    echo V Port forwarding: Done! Internal network connection is available: <WIN_IP>:18789
) else (
    echo X Port forwarding: Failed. Please run this bat file as a system administrator.
)
echo.
echo Current settings:
netsh interface portproxy show v4tov4 | findstr 18789
echo.
```

## 如何連線?

* 瀏覽器 http://<WIN_IP>:18789

## 完成後常用指令

- `openclaw --version` → 確認安裝
- `openclaw onboard` → 重新跑設定
- `openclaw gateway status` → 檢查狀態
- `openclaw doctor` → 診斷問題

## 參考文章

WSL 開機啟動並持續運行 (透過背景運行SSH)


留言

這個網誌中的熱門文章

出國旅遊 基本配備一: 轉接頭+變壓器 (避免燒掉 吹風機/電棒)

出國旅遊 基本配備四: 壓縮袋 (避免 「空間不足」)

出國旅遊 基本配備二: 延長線 (避免 「搶插座」)