1ttyd(1) User Manual ttyd(1)
2
3
4
6 ttyd - Share your terminal over the web
7
8
9
11 ttyd [options] <command> [<arguments...>]
12
13
14
16 ttyd is a command-line tool for sharing terminal over the web that runs
17 in *nix and windows systems, with the following features:
18
19 · Built on top of Libwebsockets with libuv for speed
20
21 · Fully-featured terminal based on Xterm.js with CJK (Chinese, Japa‐
22 nese, Korean) and IME support
23
24 · Graphical ZMODEM integration with lrzsz support
25
26 · SSL support based on OpenSSL
27
28 · Run any custom command with options
29
30 · Basic authentication support and many other custom options
31
32 · Cross platform: macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows
33
34
35
37 -p, --port <port>
38 Port to listen (default: 7681, use 0 for random port)
39
40
41 -i, --interface <interface>
42 Network interface to bind (eg: eth0), or UNIX domain socket path
43 (eg: /var/run/ttyd.sock)
44
45
46 -c, --credential USER[:PASSWORD]
47 Credential for Basic Authentication (format: username:password)
48
49
50 -u, --uid <uid>
51 User id to run with
52
53
54 -g, --gid <gid>
55 Group id to run with
56
57
58 -s, --signal <signal string>
59 Signal to send to the command when exit it (default: 1, SIGHUP)
60
61
62 -a, --url-arg
63 Allow client to send command line arguments in URL (eg:
64 ⟨http://localhost:7681?arg=foo&arg=bar⟩)
65
66
67 -R, --readonly
68 Do not allow clients to write to the TTY
69
70
71 -t, --client-option <key=value>
72 Send option to client (format: key=value), repeat to add more
73 options
74
75
76 -T, --terminal-type
77 Terminal type to report, default: xterm-256color
78
79
80 -O, --check-origin
81 Do not allow websocket connection from different origin
82
83
84 -m, --max-clients
85 Maximum clients to support (default: 0, no limit)
86
87
88 -o, --once
89 Accept only one client and exit on disconnection
90
91
92 -B, --browser
93 Open terminal with the default system browser
94
95
96 -I, --index <index file>
97 Custom index.html path
98
99
100 -b, --base-path
101 Expected base path for requests coming from a reverse proxy (eg:
102 /mounted/here)
103
104
105 -6, --ipv6
106 Enable IPv6 support
107
108
109 -S, --ssl
110 Enable SSL
111
112
113 -C, --ssl-cert <cert path>
114 SSL certificate file path
115
116
117 -K, --ssl-key <key path>
118 SSL key file path
119
120
121 -A, --ssl-ca <ca path>
122 SSL CA file path for client certificate verification
123
124
125 -d, --debug <level>
126 Set log level (default: 7)
127
128
129 -v, --version
130 Print the version and exit
131
132
133 -h, --help
134 Print this text and exit
135
136
137
139 ttyd starts web server at port 7681 by default, you can use the -p
140 option to change it, the command will be started with arguments as
141 options. For example, run:
142
143
144 ttyd -p 8080 bash -x
145
146
147
148 Then open ⟨http://localhost:8080⟩ with a browser, you will get a bash
149 shell with debug mode enabled. More examples:
150
151 · If you want to login with your system accounts on the web browser,
152 run ttyd login.
153
154 · You can even run a none shell command like vim, try: ttyd vim, the
155 web browser will show you a vim editor.
156
157 · Sharing single process with multiple clients: ttyd tmux new -A -s
158 ttyd vim, run tmux new -A -s ttyd to connect to the tmux session from
159 terminal.
160
161
162
164 Generate SSL CA and self signed server/client certificates:
165
166
167 # CA certificate (FQDN must be different from server/client)
168 openssl genrsa -out ca.key 2048
169 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
170
171 # server certificate (for multiple domains, change subjectAltName to: DNS:example.com,DNS:www.example.com)
172 openssl req -newkey rsa:2048 -nodes -keyout server.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=localhost" -out server.csr
173 openssl x509 -sha256 -req -extfile <(printf "subjectAltName=DNS:localhost") -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt
174
175 # client certificate (the p12/pem format may be useful for some clients)
176 openssl req -newkey rsa:2048 -nodes -keyout client.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=client" -out client.csr
177 openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt
178 openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12
179 openssl pkcs12 -in client.p12 -out client.pem -clcerts
180
181
182
183 Then start ttyd:
184
185
186 ttyd --ssl --ssl-cert server.crt --ssl-key server.key --ssl-ca ca.crt bash
187
188
189
190 You may want to test the client certificate verification with curl(1):
191
192
193 curl --insecure --cert client.p12[:password] -v https://localhost:7681
194
195
196
197 If you don't want to enable client certificate verification, remove the
198 --ssl-ca option.
199
200
201
203 Docker containers are jailed environments which are more secure, this
204 is useful for protecting the host system, you may use ttyd with docker
205 like this:
206
207 · Sharing single docker container with multiple clients: docker run -it
208 --rm -p 7681:7681 tsl0922/ttyd.
209
210 · Creating new docker container for each client: ttyd docker run -it
211 --rm ubuntu.
212
213
214
216 Sample config to proxy ttyd under the /ttyd path:
217
218
219 location ^/ttyd(.*)$ {
220 proxy_http_version 1.1;
221 proxy_set_header Host $host;
222 proxy_set_header X-Forwarded-Proto $scheme;
223 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
224 proxy_set_header Upgrade $http_upgrade;
225 proxy_set_header Connection "upgrade";
226 proxy_pass http://127.0.0.1:7681/$1;
227 }
228
229
230
231
233 Shuanglei Tao <tsl0922@gmail.com> Visit
234 ⟨https://github.com/tsl0922/ttyd⟩ to get more information and report
235 bugs.
236
237
238
239ttyd September 2016 ttyd(1)