項目網址
Awesome DeepSeek Harnesshttps://github.com/0xsline/awesome-deepseek-harness
DeepSeek Harness Ultimatehttps://github.com/18126295767-cell/deepseek-harness-ultimate
同一个模型,装一个插件前后判若两个 AI:DeepSeek 到底开源了什么? | 回到Axton
DeepSeek Harness插件完全指南:找、装、管、造四步搞定(附十大必装插件盘点)

Agentic 智慧體 VPS 伺服器部署 Apache 2.4 反向代理 WebSocket 穿透 資安加固

DeepSeek Harness (dsh) 遠端 VPS 伺服器安裝與 Apache 安全加固實戰指南

銜接 InferNews 介紹之 DeepSeek Harness 核心特性:Harness 具備自主呼叫終端機(Bash)、讀寫檔案與外掛插件權限。若要部署於公網 VPS,必須建立嚴格的 Apache TLS 加密、WebSocket 軌跡雙向轉發、HTTP 身分驗證閘門與 Linux 沙盒限制。

⚠️【資安警示】為什麼不能把 DeepSeek Harness 預設通訊埠直接暴露至公網? DeepSeek Harness 具備自主智慧體代碼生成、外掛執行與 Bash Shell 命令執行能力。若您僅使用 dsh web 監聽 0.0.0.0 且無任何身分驗證,任何掃描到您 IP 的訪客都能直接在您的 VPS 上執行任意指令!本指南透過「UFW 阻斷直接連線 + 127.0.0.1 本地回環綁定 + Apache TLS 雙層認證 + Systemd 沙盒」四道防線徹底阻絕風險。

1 主機初始化、非 Root 帳號與 UFW 防火牆配置

建立專用隔離運維帳號 dshops,並設定 UFW 防火牆規則。特別注意:必須明確阻斷外部對 Harness 通訊埠 3080 的直接連線,僅允許 HTTP/HTTPS 透過 Apache 入口轉發。

Terminal — 系統升級與防火牆阻斷
# 1. 更新系統套件與安裝基礎防護模組
sudo apt update && sudo apt upgrade -y
sudo apt install -y ufw fail2ban curl wget git htop apache2-utils build-essential

# 2. 建立專用隔離運維使用者 (不給予直接登入 Shell 核心權限)
sudo useradd -m -s /bin/bash dshops
sudo usermod -aG sudo dshops

# 3. 配置 UFW 防火牆(預設拒絕所有傳入連線)
sudo ufw default deny incoming
sudo ufw default allow outgoing

# 只開放管理 SSH 與 Web 通訊埠
sudo ufw allow 22/tcp comment 'SSH 管理'
sudo ufw allow 80/tcp comment 'HTTP 驗證'
sudo ufw allow 443/tcp comment 'HTTPS 加密'

# 核心安全:明確拒絕外網直探 Harness 後端
sudo ufw deny 3080/tcp comment '拒絕外部直連 DeepSeek Harness'

# 啟用防火牆並檢驗狀態
sudo ufw --force enable
sudo ufw status verbose

2 安裝 Node.js 22 LTS 與 DeepSeek Harness CLI

DeepSeek Harness 需要 Node.js 20 以上環境。我們透過 NodeSource 安裝最新的 Node.js 22 LTS,並安裝官方套件 @deepseek-ai/dsh 與隔離工作目錄。

Terminal — 安裝 Node.js 與 Harness 核心
# 1. 導入 NodeSource Node.js 22.x LTS 套件庫
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs

# 驗證版本是否 >= v20.0.0
node -v && npm -v

# 2. 全域安裝 pnpm 與 DeepSeek Harness CLI
sudo npm install -g pnpm @deepseek-ai/dsh

# 3. 建立專屬運作與智慧體工作目錄 (Workspaces Jail)
sudo mkdir -p /var/lib/deepseek-harness/workspaces
sudo chown -R dshops:dshops /var/lib/deepseek-harness
sudo chmod 750 /var/lib/deepseek-harness

3 配置 Systemd 背景服務與 Linux 核心層級沙盒隔離

為防止 Harness 在執行自主代碼時意外存取到系統核心敏感檔案,我們在 Systemd 服務中加入 ProtectSystem=fullProtectHome=read-onlyNoNewPrivileges=true。同時強制將 Web 服務綁定在本地回環介面 127.0.0.1:3080

/etc/systemd/system/dsh-web.service
# 建立 Systemd 服務單元檔
sudo bash -c 'cat << "EOF" > /etc/systemd/system/dsh-web.service
[Unit]
Description=DeepSeek Harness (dsh) Web Service
After=network.target

[Service]
Type=simple
User=dshops
Group=dshops
WorkingDirectory=/var/lib/deepseek-harness

# 關鍵環境變數(僅監聽本地 127.0.0.1)
Environment="NODE_ENV=production"
Environment="HOST=127.0.0.1"
Environment="PORT=3080"
Environment="DEEPSEEK_API_KEY=sk-dseek-v4flash-sample-key-12345"
Environment="DSH_WORKSPACE_ROOT=/var/lib/deepseek-harness/workspaces"

# 啟動命令:本地 Web 模式,不呼叫桌面圖形瀏覽器
ExecStart=/usr/bin/npx @deepseek-ai/dsh web --no-open --host 127.0.0.1 --port 3080
Restart=always
RestartSec=5

# Linux 核心安全沙盒隔離保護
ProtectSystem=full
ProtectHome=read-only
PrivateTmp=true
ProtectKernelTunables=true
ProtectControlGroups=true
NoNewPrivileges=true
ReadWritePaths=/var/lib/deepseek-harness /tmp

[Install]
WantedBy=multi-user.target
EOF'

# 載入並啟動服務
sudo systemctl daemon-reload
sudo systemctl enable dsh-web
sudo systemctl restart dsh-web

# 檢查確認僅監聽 127.0.0.1 (絕不可出現 0.0.0.0)
sudo ss -tulpn | grep 3080

4 安裝 Apache 並啟用 WebSocket (proxy_wstunnel) 雙向代理模組

DeepSeek Harness 的 Web UI 不僅傳輸靜態頁面,還依賴 WebSocket 雙向通道串流傳輸智慧體的推理思考軌跡(Trajectory)、終端機輸出與 Token 串流。因此 Apache 必須載入 proxy_wstunnel 模組。

Terminal — Apache 模組啟用與初始網站設定
# 1. 安裝 Apache 伺服器
sudo apt install -y apache2

# 2. 啟用反向代理、WebSocket 穿透與安全模組
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel
sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod ssl
sudo a2enmod auth_basic

# 3. 停用預設網站並建立初步 HTTP 虛擬主機
sudo a2dissite 000-default.conf

sudo bash -c 'cat << "EOF" > /etc/apache2/sites-available/dsh.conf
<VirtualHost *:80>
    ServerName dsh.infernews.com
    ServerAdmin admin@infernews.com

    ServerSignature Off
    ProxyPreserveHost On
    ProxyRequests Off

    ProxyPass / http://127.0.0.1:3080/
    ProxyPassReverse / http://127.0.0.1:3080/

    ErrorLog ${APACHE_LOG_DIR}/dsh_error.log
    CustomLog ${APACHE_LOG_DIR}/dsh_access.log combined
</VirtualHost>
EOF'

sudo a2ensite dsh.conf
sudo apache2ctl configtest
sudo systemctl restart apache2

5 Let’s Encrypt TLS 憑證與 Apache HTTP Auth 身分閘門

透過 Certbot 自動簽署 HTTPS 憑證,並利用 Apache 的 .htpasswd 建立第一道帳號密碼保護閘門。未通過密碼驗證者,連 Harness 的載入畫面都無法探測。

/etc/apache2/sites-available/dsh-le-ssl.conf
# 1. 建立 Web 閘門 bcrypt 強密碼
sudo mkdir -p /etc/apache2/auth
sudo htpasswd -B -c /etc/apache2/auth/.htpasswd admin
sudo chown -R root:www-data /etc/apache2/auth
sudo chmod 640 /etc/apache2/auth/.htpasswd

# 2. 安裝 Certbot 申請免費 Let's Encrypt 憑證
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache \
  --agree-tos \
  --redirect \
  --no-eff-email \
  --email admin@infernews.com \
  -d dsh.infernews.com

# 3. 部署最終生產加固配置 (含 WebSocket 穿透與 Basic Auth 閘門)
sudo bash -c 'cat << "EOF" > /etc/apache2/sites-available/dsh-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName dsh.infernews.com
    ServerAdmin admin@infernews.com

    # 資安防禦 Header
    Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header unset Server
    ServerSignature Off

    # 防止長請求阻斷
    LimitRequestBody 20971520

    # 啟用 Rewrite 處理 WebSocket 升級請求 (關鍵:Trajectory 即時串流)
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /(.*) ws://127.0.0.1:3080/$1 [P,L]

    # 取消代理緩衝,確保長文本與即時推理 Token 串流不延遲
    SetEnv proxy-nokeepalive 1
    SetEnv proxy-initial-not-buffered 1
    Timeout 600
    ProxyTimeout 600

    # Web UI 第一道身分保護閘門
    <Location "/">
        AuthType Basic
        AuthName "DeepSeek Harness Protected"
        AuthUserFile /etc/apache2/auth/.htpasswd
        Require valid-user

        ProxyPass http://127.0.0.1:3080/
        ProxyPassReverse http://127.0.0.1:3080/
    </Location>

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/dsh.infernews.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/dsh.infernews.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    ErrorLog ${APACHE_LOG_DIR}/dsh_ssl_error.log
    CustomLog ${APACHE_LOG_DIR}/dsh_ssl_access.log combined
</VirtualHost>
</IfModule>
EOF'

# 語法驗證並重載 Apache
sudo apache2ctl configtest && sudo systemctl reload apache2

6 Fail2ban 自動封鎖密碼暴力破解攻擊

配置 Fail2ban 監控 Apache 的錯誤認證日誌。若攻擊者連續 3 次輸入錯誤密碼,自動透過 iptables 封鎖其 IP 24 小時。

/etc/fail2ban/jail.d/dsh-apache.local
sudo bash -c 'cat << "EOF" > /etc/fail2ban/jail.d/dsh-apache.local
[apache-auth]
enabled = true
port = http,https
filter = apache-auth
logpath = /var/log/apache2/*error.log
maxretry = 3
findtime = 10m
bantime = 24h
EOF'

sudo systemctl restart fail2ban
sudo fail2ban-client status apache-auth

7 連線健康檢查與未授權阻斷驗證

透過終端機執行驗證,確認「未帶帳號密碼時是否返回 401 Unauthorized」以及「攜帶認證後是否能成功穿透 WebSocket 進入 Harness 介面」。

Terminal — 連線驗證測試
# 測試 1:未認證存取測試(預期返回:HTTP 401 Unauthorized)
curl -I -s https://dsh.infernews.com/ | grep "HTTP/"

# 測試 2:帶入認證存取測試(替換為實際密碼,預期返回:HTTP 200 OK)
curl -u admin:YOUR_PASSWORD -I https://dsh.infernews.com/

# 測試 3:即時監控 Harness 背景服務軌跡與智慧體日誌
sudo journalctl -u dsh-web.service -f

DeepSeek Harness 生產環境上線安全檢查表

僅綁定 127.0.0.1:3080(禁止 0.0.0.0)
UFW 防火牆阻斷外部直連通訊埠 3080
Apache 啟用 proxy_wstunnel 雙向串流
強制 HTTPS (TLS 1.3) 與 HSTS 回應標頭
HTTP Basic Auth 帳號密碼閘門保護
Systemd 沙盒隔離 (ProtectSystem=full)

© InferNews 技術特輯 • 本文章內容專供 WordPress 文章追加嵌入使用。