A web-based terminal that connects your browser to a server-side shell using a PTY bridge and WebSocket, rendered with xterm.js. All assets and the WebSocket endpoint are served under the /xterm prefix.
Open http://localhost:8089/xterm/ in your browser.
- Real-time terminal via PTY (
creack/pty) and WebSocket (melody). - Embedded static assets using Go
embed(no external static server needed). - Optional Basic Auth with sliding window cookie session (30 min by default).
- Configurable server address and shell command via CLI flags (Cobra).
- All resources under
/xtermprefix; WebSocket at/xterm/webterminal. - Front-end powered by
xtermandxterm-addon-fitwith auto-resize.
- Go 1.22+
- A modern browser
- Clone:
git clone https://github.com/garfcat/webterminal.git
cd webterminal- Install Go dependencies:
go mod tidy- Run server (no auth):
go run main.go- Open:
http://localhost:8089/xterm/
go run main.go \
--auth \
--username admin \
--password secret \
--addr 0.0.0.0:8089 \
--shell bash--addr(default0.0.0.0:8089): Server listen address.--auth(defaultfalse): Enable Basic Auth + session cookie (session_id).--username(defaultadmin): Username for Basic Auth.--password(defaultpassword): Password for Basic Auth.--shell(defaultsh): Shell to launch inside the PTY.
- Web page:
/xterm/ - WebSocket endpoint:
/xterm/webterminal - Static assets (example):
/xterm/node_modules/xterm/lib/xterm.js
This application exposes a direct shell. For production usages:
- Always enable
--authand use a strong password. - Serve behind TLS (use a reverse proxy) so that WebSocket upgrades use
wss://. - Consider restricting the shell to a non-privileged user.
- Review audit, access control, and environment isolation as needed.
- Front-end uses
xtermandxterm-addon-fitfromstatic/node_modules. If you need to update front-end dependencies, runnpm installunderstatic/. - For production, consider bundling/minifying and embedding only built assets.
一个基于浏览器的 Web 终端,通过 PTY 与 WebSocket 将浏览器与服务端 Shell 连接,并使用 xterm.js 渲染终端界面。所有资源与接口均位于 /xterm 前缀下。
浏览器打开:http://localhost:8089/xterm/
- 通过
creack/pty与melody实现实时终端与 WebSocket 双向传输。 - 使用 Go
embed内嵌静态资源,无需额外静态服务器。 - 可选 Basic Auth 与会话 Cookie(默认 30 分钟滑动过期)。
- 通过 Cobra 提供命令行参数,支持自定义监听地址与 Shell。
- 所有资源挂载到
/xterm;WebSocket 端点为/xterm/webterminal。 - 前端基于
xterm与xterm-addon-fit,自动适配窗口大小。
- Go 1.22+
- 现代浏览器
1)克隆项目:
git clone https://github.com/garfcat/webterminal.git
cd webterminal2)安装 Go 依赖:
go mod tidy3)启动(无认证):
go run main.go4)访问:
http://localhost:8089/xterm/
go run main.go \
--auth \
--username admin \
--password secret \
--addr 0.0.0.0:8089 \
--shell bash--addr(默认0.0.0.0:8089):服务监听地址。--auth(默认false):启用 Basic Auth 与会话 Cookie(session_id)。--username(默认admin):认证用户名。--password(默认password):认证密码。--shell(默认sh):启动的 Shell 程序。
- 页面入口:
/xterm/ - WebSocket:
/xterm/webterminal - 静态资源示例:
/xterm/node_modules/xterm/lib/xterm.js
- 生产环境务必开启
--auth并设置强口令。 - 通过反向代理启用 TLS(从而使用
wss://)。 - 使用受限用户运行 Shell,降低风险面。
- 结合实际需求完善访问控制、审计与隔离策略。
- 前端依赖位于
static/node_modules,如需更新可在static/目录执行npm install。 - 生产部署建议打包与最小化,仅嵌入构建产物。