Web Shell 是一个 Go 单二进制网页终端:Web UI/API 通过独立 webshell sessiond 守护进程管理本机 shell PTY,前端用 xterm.js 渲染终端,并提供指定目录内的文件浏览、上传、下载。
- 浏览器终端,基于 xterm.js
- 独立 sessiond + 轻量 session worker 持有 PTY,无需 tmux;webshell 主进程重启后可重新接回
- 多 shell 会话管理、重命名、关闭
- 指定根目录内的文件浏览、上传、下载
- 支持 OpenResty/Nginx 反向代理和 WebSocket 转发
下载对应架构的二进制:
# x86_64 / amd64
curl -L -o webshell https://github.com/systemime/web_shell/releases/latest/download/webshell-linux-amd64
# arm64 / aarch64
curl -L -o webshell https://github.com/systemime/web_shell/releases/latest/download/webshell-linux-arm64
chmod +x webshell启动:
# 先启动独立会话守护进程
WEB_WORKER_ROOT=/opt ./webshell sessiond &# 再启动 Web UI/API
WEB_WORKER_ROOT=/opt ./webshell默认监听:
http://127.0.0.1:8787
常用环境变量:
| 变量 | 默认值 | 说明 |
|---|---|---|
HOST | 127.0.0.1 | 监听地址 |
PORT | 8787 | 监听端口 |
WEB_WORKER_ROOT | 当前目录 | 网页可访问的文件根目录 |
WEB_WORKER_MAX_UPLOAD_MB | 100 | 单文件上传大小限制 |
SHELL | /bin/bash | 新建 shell 使用的程序 |
会话说明:
- shell 由独立
webshell sessiond守护进程管理,PTY 仍由轻量session-worker持有,元数据和 Unix socket 放在.web-worker-sessions/。 - systemd 配置里的
webshell.service依赖webshell-sessiond.service;重启主webshell不会重启 sessiond,因此重新部署后可恢复已有终端。 - 如果手动杀掉
session-worker、重启机器,或把 systemd 改回KillMode=control-group,对应终端仍会结束。
推荐公网只暴露代理端口,让 Web Shell 继续监听本机 127.0.0.1:8787。
sudo install -m 755 webshell /opt/project/web_worker/webshell
sudo install -m 600 /dev/null /etc/webshell.env
sudo tee /etc/webshell.env >/dev/null <<'EOF_ENV'HOST=127.0.0.1PORT=8787WEB_WORKER_ROOT=/optWEB_WORKER_MAX_UPLOAD_MB=100SHELL=/bin/bashEOF_ENV
sudo tee /etc/systemd/system/webshell-sessiond.service >/dev/null <<'EOF_SESSIOND'[Unit]Description=Web Shell Session DaemonAfter=network.target[Service]Type=simpleWorkingDirectory=/opt/project/web_workerEnvironmentFile=/etc/webshell.envExecStart=/opt/project/web_worker/webshell sessiondKillMode=processRestart=alwaysRestartSec=2[Install]WantedBy=multi-user.targetEOF_SESSIOND
sudo tee /etc/systemd/system/webshell.service >/dev/null <<'EOF_SERVICE'[Unit]Description=Web ShellRequires=webshell-sessiond.serviceAfter=network.target webshell-sessiond.service[Service]Type=simpleWorkingDirectory=/opt/project/web_workerEnvironmentFile=/etc/webshell.envExecStart=/opt/project/web_worker/webshellKillMode=processRestart=alwaysRestartSec=2[Install]WantedBy=multi-user.targetEOF_SERVICE
sudo systemctl daemon-reload
sudo systemctl enable --now webshell-sessiond webshell下面示例监听 18787,代理到本机 8787,并支持 WebSocket:
map$http_upgrade$connection_upgrade{
default upgrade;'' close;}server{listen18787ssl;server_name _;ssl_certificate /path/to/fullchain.pem;ssl_certificate_key /path/to/privkey.pem;client_max_body_size100m;location / {proxy_passhttp://127.0.0.1:8787;proxy_http_version 1.1;proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection $connection_upgrade;proxy_read_timeout1d;proxy_send_timeout1d;proxy_buffering off;}}重载代理:
sudo nginx -t && sudo systemctl reload nginx
# 或 OpenResty:
sudo openresty -t && sudo openresty -s reload访问:
https://服务器IP或域名:18787