跳到正文
发现
ttyd:把终端分享到网页
命令行工具开发者工具

ttyd:把终端分享到网页

一个命令行工具,把终端共享到浏览器中访问,支持跨平台的 Web 终端。

admin
发布于 2026-10-28
浏览
4
访问
0
下载
0
版本
v1.7.7
平台
Windows、macOS、Linux
该作品还没有经过官方审核。访问演示、下载或复制命令前,请自行确认来源可信。

详细介绍

项目简介

ttyd 是一个简单的命令行工具,用于在网页上分享你的终端。它基于 libuv 和 WebGL2 构建,注重速度;跨平台支持 macOS、Linux、FreeBSD/OpenBSD、OpenWrt 和 Windows,采用 MIT 许可证开源。

主要功能

  • 基于 libuv 和 WebGL2,性能出色
  • 功能完整的终端,支持 CJK 字符与输入法(IME)
  • 支持 ZMODEM(lrzsz)/ trzsz 文件传输
  • 支持 Sixel 图片输出(img2sixel / lsix)
  • 基于 OpenSSL / Mbed TLS 的 SSL 支持
  • 可通过参数运行任意自定义命令
  • 支持基础认证与多种自定义选项

安装与使用

macOS

  • Homebrew:brew install ttyd
  • MacPorts:sudo port install ttyd

Linux

  • Debian/Ubuntu:sudo apt install ttyd
  • Snap:sudo snap install ttyd --classic
  • OpenWrt:opkg install ttyd
  • Homebrew:brew install ttyd
  • 预编译静态二进制:从 releases 页面下载

Windows

  • 二进制版本(推荐):从 releases 页面下载
  • WinGet:winget install tsl0922.ttyd
  • Scoop:scoop install ttyd

命令行用法

USAGE:
    ttyd [options] <command> [<arguments...>]

OPTIONS:
    -p, --port              Port to listen (default: 7681, use `0` for random port)
    -i, --interface         Network interface to bind (eg: eth0), or UNIX domain socket path (eg: /var/run/ttyd.sock)
    -U, --socket-owner      User owner of the UNIX domain socket file, when enabled (eg: user:group)
    -c, --credential        Credential for basic authentication (format: username:password)
    -H, --auth-header       HTTP Header name for auth proxy, this will configure ttyd to let a HTTP reverse proxy handle authentication
    -u, --uid               User id to run with
    -g, --gid               Group id to run with
    -s, --signal            Signal to send to the command when exit it (default: 1, SIGHUP)
    -w, --cwd               Working directory to be set for the child program
    -a, --url-arg           Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)
    -W, --writable          Allow clients to write to the TTY (readonly by default)
    -t, --client-option     Send option to client (format: key=value), repeat to add more options
    -T, --terminal-type     Terminal type to report, default: xterm-256color
    -O, --check-origin      Do not allow websocket connection from different origin
    -m, --max-clients       Maximum clients to support (default: 0, no limit)
    -o, --once              Accept only one client and exit on disconnection
    -q, --exit-no-conn      Exit on all clients disconnection
    -B, --browser           Open terminal with the default system browser
    -I, --index             Custom index.html path
    -b, --base-path         Expected base path for requests coming from a reverse proxy (eg: /mounted/here, max length: 128)
    -P, --ping-interval     Websocket ping interval(sec) (default: 5)
    -6, --ipv6              Enable IPv6 support
    -S, --ssl               Enable SSL
    -C, --ssl-cert          SSL certificate file path
    -K, --ssl-key           SSL key file path
    -A, --ssl-ca            SSL CA file path for client certificate verification
    -d, --debug             Set log level (default: 7)
    -v, --version           Print the version and exit
    -h, --help              Print this text and exit

更多示例用法参见 wiki。

注意事项

  • 默认以只读方式提供终端,需要 -W / --writable 才允许客户端写入 TTY。
  • 可通过 -c / --credential 添加基础认证,或使用 -H / --auth-header 交给 HTTP 反向代理做认证。
  • 浏览器支持情况参见 Browser Support,需要较现代的浏览器。
  • 类似的替代项目还有 Wetty(基于 Node)和 GoTTY(基于 Go)。

本作品整理自 GitHub 开源项目 tsl0922/ttyd,原作者 @tsl0922,许可证 MIT。中文介绍由 AI 根据项目 README 整理,以原仓库为准。

更新记录

  1. v1.7.7当前版本

    修复了非 git 仓库构建时的版本检测问题;在 CMake 中加回静态版本号;发布流程现在会检查 CMakeLists.txt 中的版本号是否已更新。

评论