ttyd(1)

πŸ“¦
version 1.7.7 Β· 3 versions
, in alpine 3.24, arch rolling, epel 10, epel 9, fedora 43, fedora 44, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ ttyd β€” the manual, but make it cute ✨

okay bestie, welcome to the ttyd(1) manual page πŸ’– this is the User Manual energy, and we're about to make your terminal famous on the internet. no cap.


🌸 NAME 🌸

ttyd β€” share your terminal over the web πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

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

✨ DESCRIPTION ✨

so like, ttyd is a command-line tool for sharing your terminal over the web, and it runs on nix and windows systems. she's flexible like that 🫢 and here's the feature list, because she is *stacked:

  • Built on top of Libwebsockets with libuv for speed ⚑
  • Fully-featured terminal based on Xterm.js with CJK (Chinese, Japanese, Korean) and IME support 🌏
  • Graphical ZMODEM integration with lrzsz support
  • Sixel image output support πŸ–ΌοΈ
  • SSL support based on OpenSSL πŸ”’
  • Run any custom command with options πŸ‘‘
  • Basic authentication support and many other custom options πŸ”₯
  • Cross platform: macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows 🌈

πŸ’… OPTIONS πŸ’…

every single one, bestie. no skipping. periodt.

  • -p, --port β€” port to listen on (default: 7681, use 0 for a random port) 🎲
  • -i, --interface β€” network interface to bind (eg: eth0), or a 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 USER[:PASSWORD] β€” credential for Basic Authentication (format: username:password) πŸ”
  • -H, --auth-header β€” HTTP Header name for auth proxy; this configures 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 the 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, see CLIENT OPTIONS for details
  • -T, --terminal-type β€” terminal type to report, default: xterm-256color
  • -O, --check-origin β€” do not allow websocket connection from a 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

πŸŽ€ CLIENT OPTIONS πŸŽ€

so ttyd has a little mechanism where it passes server-side command-line arguments to the browser page, and that's what we call client options πŸ’–

  • -t, --client-option β€” send option to client (format: key=value), repeat to add more options

🌟 Basic usage 🌟

  • -t rendererType=canvas β€” use the canvas renderer for xterm.js (default: webgl) 🎨
  • -t disableLeaveAlert=true β€” disable the leave page alert
  • -t disableResizeOverlay=true β€” disable the terminal resize overlay
  • -t disableReconnect=true β€” prevent the terminal from reconnecting on connection error/close
  • -t enableZmodem=true β€” enable ZMODEM / lrzsz file transfer support πŸ“¦
  • -t enableTrzsz=true β€” enable trzsz file transfer support πŸ“¦
  • -t enableSixel=true β€” enable Sixel image output support (Usage)
  • -t titleFixed=hello β€” set a fixed title for the browser window
  • -t fontSize=20 β€” change the font size of the terminal πŸ”

πŸ’« Advanced usage πŸ’«

you can use the client option to change all the settings of xterm defined in ITerminalOptions, examples:

  • -t cursorStyle=bar β€” set cursor style to bar
  • -t lineHeight=1.5 β€” set line-height to 1.5
  • -t 'theme={"background": "green"}' β€” set background color to green πŸ’š

to try the example options above, run:

ttyd -t cursorStyle=bar -t lineHeight=1.5 -t 'theme={"background": "green"}' bash

πŸ”₯ EXAMPLES πŸ”₯

ttyd starts a web server at port 7681 by default, and you can use the -p option to change it. the command will be started with arguments as options. for example, run:

ttyd -p 8080 bash -x

then open http://localhost:8080 with a browser, and you will get a bash shell with debug mode enabled. more examples:

  • if you want to login with your system accounts on the web browser, run ttyd login.
  • you can even run a none shell command like vim, try: ttyd vim, and the web browser will show you a vim editor πŸ‘‘
  • sharing single process with multiple clients: ttyd tmux new -A -s ttyd vim, run tmux new -A -s ttyd to connect to the tmux session from terminal.

πŸ”’ SSL how-to πŸ”’

generate SSL CA and self signed server/client certificates:

# CA certificate (FQDN must be different from server/client)
openssl genrsa -out ca.key 2048
openssl req -new -x509 -days 365 -key ca.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=Acme Root CA" -out ca.crt

# server certificate (for multiple domains, change subjectAltName to: DNS:example.com,DNS:www.example.com)
openssl req -newkey rsa:2048 -nodes -keyout server.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=localhost" -out server.csr
openssl x509 -sha256 -req -extfile <(printf "subjectAltName=DNS:localhost") -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt

# client certificate (the p12/pem format may be useful for some clients)
openssl req -newkey rsa:2048 -nodes -keyout client.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=client" -out client.csr
openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt
openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12
openssl pkcs12 -in client.p12 -out client.pem -clcerts

then start ttyd:

ttyd --ssl --ssl-cert server.crt --ssl-key server.key --ssl-ca ca.crt bash

you may want to test the client certificate verification with curl(1):

curl --insecure --cert client.p12[:password] -v https://localhost:7681

if you don't want to enable client certificate verification, remove the --ssl-ca option.

🐳 Docker and ttyd 🐳

Docker containers are jailed environments which are more secure, and this is useful for protecting the host system. you may use ttyd with docker like this:

  • sharing single docker container with multiple clients: docker run -it --rm -p 7681:7681 tsl0922/ttyd.
  • creating new docker container for each client: ttyd docker run -it --rm ubuntu.

🌈 Nginx reverse proxy 🌈

sample config to proxy ttyd under the /ttyd path:

location ~ ^/ttyd(.*)$ {
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://127.0.0.1:7681/$1;
}

πŸ‘‘ AUTHOR πŸ‘‘

Shuanglei Tao <tsl0922@gmail.com> β€” visit https://github.com/tsl0922/ttyd to get more information and report bugs πŸ›


and that's the whole manual, bestie πŸ’– this is ttyd version ttyd(1) from way back in September 2016 β€” iconic behavior honestly. now go share that terminal, you main character 🫢✨