{"id":356,"date":"2022-08-20T11:03:00","date_gmt":"2022-08-20T03:03:00","guid":{"rendered":"http:\/\/www.tyhlw.org\/?p=356"},"modified":"2022-08-20T11:06:08","modified_gmt":"2022-08-20T03:06:08","slug":"linux-web-terminal-ttyd","status":"publish","type":"post","link":"https:\/\/www.tyhlw.org\/?p=356","title":{"rendered":"Linux Web Terminal&#8212;-ttyd"},"content":{"rendered":"<p>ttyd\u662f\u4e00\u6b3e\u53ef\u4ee5\u5c06\u547d\u4ee4\u884c\u8f6c\u5230 Web \u6267\u884c\u7684\u5de5\u5177\uff0c\u57fa\u4e8e C \u7f16\u5199\u7684\u3002<\/p>\n<p>https:\/\/github.com\/tsl0922\/ttyd<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.tyhlw.org\/wp-content\/uploads\/2022\/08\/7aba0faad99325edd3a626d60328543a.jpg\" alt=\"\" width=\"600\" height=\"369\" class=\"aligncenter size-full wp-image-358\" srcset=\"https:\/\/www.tyhlw.org\/wp-content\/uploads\/2022\/08\/7aba0faad99325edd3a626d60328543a.jpg 600w, https:\/\/www.tyhlw.org\/wp-content\/uploads\/2022\/08\/7aba0faad99325edd3a626d60328543a-300x185.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2 dir=\"auto\">\u5b89\u88c5 on macOS<\/h2>\n<p dir=\"auto\">Install with<span>\u00a0<\/span><a href=\"http:\/\/brew.sh\/\" rel=\"nofollow\">homebrew<\/a>:<\/p>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\">\n<pre>brew install ttyd<\/pre>\n<\/div>\n<h2 dir=\"auto\">\u5b89\u88c5 on Linux<\/h2>\n<p dir=\"auto\">Binary version :<br \/>\n\u4e0b\u8f7d\u6700\u65b0\u72481.7.1\u00a0 https:\/\/github.com\/tsl0922\/ttyd\/releases<\/p>\n<p dir=\"auto\">\u6e90\u7801\u5b89\u88c5 (debian\/ubuntu):<\/p>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\">\n<pre>sudo apt-get install build-essential cmake git libjson-c-dev libwebsockets-dev\r\ngit clone https:\/\/github.com\/tsl0922\/ttyd.git\r\n<span class=\"pl-c1\">cd<\/span> ttyd <span class=\"pl-k\">&amp;&amp;<\/span> mkdir build <span class=\"pl-k\">&amp;&amp;<\/span> <span class=\"pl-c1\">cd<\/span> build\r\ncmake ..\r\nmake <span class=\"pl-k\">&amp;&amp;<\/span> sudo make install<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2 dir=\"auto\">\u5b89\u88c5 on OpenWrt<\/h2>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\">\n<pre>opkg install ttyd<\/pre>\n<\/div>\n<h2 dir=\"auto\">\u8be6\u7ec6\u7528\u6cd5<\/h2>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u4e0d\u7528 bash\uff0c\u7528\u81ea\u5df1\u559c\u6b22\u7684 Shell\uff0c\u6bd4\u5982 zsh\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<div class=\"hljs-cto code-style\">\n<div class=\"hljs-cto\">\n<pre class=\"has-pre-numbering\"><code class=\"language-\"><span>ttyd\u00a0zsh\u00a0<\/span>\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u7684\u8bdd\u6d4f\u89c8\u5668\u91cc\u9762\u7684 Shell \u5c31\u662f zsh \u5566\uff1a<\/p>\n<\/div>\n<\/div>\n<p><a href=\"https:\/\/s4.51cto.com\/oss\/202201\/04\/5ed673cbcc473f3bdf67f9569ab8a446.jpg\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/s4.51cto.com\/oss\/202201\/04\/5ed673cbcc473f3bdf67f9569ab8a446.jpg\" width=\"auto\" border=\"0\" height=\"auto\" alt=\"\" title=\"\" \/><\/a><strong>\u7ed1\u5b9a\u7aef\u53e3<\/strong><\/p>\n<p>\u5f53\u7136\u6211\u4eec\u4e5f\u53ef\u4ee5\u66f4\u6362\u7aef\u53e3\uff0c\u6bd4\u5982 8000\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<div class=\"hljs-cto code-style\">\n<div class=\"hljs-cto\">\n<pre class=\"has-pre-numbering\"><code class=\"language-\"><span>ttyd\u00a0-p\u00a08000\u00a0zsh\u00a0<\/span>\r\n<\/code><\/pre>\n<p>\u8fd9\u6837 ttyd \u5c31\u53ef\u4ee5\u5728 8000 \u7aef\u53e3\u8fd0\u884c HTTP \u670d\u52a1\uff0c\u6211\u4eec\u6253\u5f00 http:\/\/localhost:8000\/ \u5c31\u53ef\u4ee5\u6267\u884c\u547d\u4ee4\u4e86\u3002<\/p>\n<\/div>\n<\/div>\n<p><strong>Basic Auth<\/strong><\/p>\n<p>\u5f53\u7136\u8fd9\u4e48\u76f4\u63a5\u66b4\u9732\u51fa\u53bb\u4f3c\u4e4e\u4e5f\u4e0d\u592a\u5b89\u5168\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6e Basic Auth\uff0c\u4f7f\u7528 -c \u8fd9\u4e2a\u9009\u9879\u5373\u53ef\u6307\u5b9a\u7528\u6237\u540d\u5bc6\u7801\uff0c\u683c\u5f0f\u4e3a username:password\uff0c\u4f8b\u5982\u6211\u4eec\u6307\u5b9a\u7528\u6237\u540d\u548c\u5bc6\u7801\u90fd\u662f admin\uff0c\u90a3\u547d\u4ee4\u5c31\u8fd9\u4e48\u5199\uff1a<\/p>\n<div class=\"hljs-cto code-style\">\n<div class=\"hljs-cto\">\n<pre class=\"has-pre-numbering\"><code class=\"language-\"><span>ttyd\u00a0-p\u00a08000\u00a0-c\u00a0admin:admin\u00a0zsh\u00a0<\/span>\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u6253\u5f00\u00a0 http:\/\/localhost:8000\/ \u4e4b\u540e\u5c31\u9700\u8981\u8f93\u5165\u7528\u6237\u540d\u5bc6\u7801\u624d\u53ef\u4ee5\u767b\u5f55\u4e86\uff1a<\/p>\n<\/div>\n<\/div>\n<p><strong>\u81ea\u52a8\u6253\u5f00\u6d4f\u89c8\u5668<\/strong><\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528 -B \u547d\u4ee4\u8ba9\u5b83\u81ea\u52a8\u6253\u5f00\u6d4f\u89c8\u5668\uff1a<\/p>\n<div class=\"hljs-cto code-style\">\n<div class=\"hljs-cto\">\n<pre class=\"has-pre-numbering\"><code class=\"language-\"><span>ttyd\u00a0-p\u00a08000\u00a0-B\u00a0zsh\u00a0<\/span>\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u8fd0\u884c\u4e4b\u540e\uff0c\u9ed8\u8ba4\u7684\u6d4f\u89c8\u5668\u5c31\u4f1a\u81ea\u52a8\u6253\u5f00 http:\/\/localhost:8000\/\uff0c\u4e0d\u7528\u6211\u4eec\u518d\u53bb\u6572\u7f51\u5740\u4e86\uff0c\u5341\u5206\u65b9\u4fbf\u3002<\/p>\n<\/div>\n<\/div>\n<p>\u6240\u4ee5\uff0c\u4e0a\u9762\u8fd9\u4e2a\u547d\u4ee4\u751a\u81f3\u6211\u4eec\u8fd8\u53ef\u4ee5\u505a\u6210\u4e00\u4e2a alias\uff0c\u6bd4\u5982\uff1a<\/p>\n<div class=\"hljs-cto code-style\">\n<div class=\"hljs-cto\">\n<pre class=\"has-pre-numbering\"><code class=\"language-\"><span>alias\u00a0<span class=\"attribute\">webcmd<\/span>=<span class=\"attribute-value\">\"ttyd\u00a0-p\u00a08000\u00a0-B\u00a0zsh\"<\/span>;\u00a0<\/span>\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u8f93\u5165 webcmd \u5c31\u53ef\u4ee5\u8f7b\u677e\u6253\u5f00\u4e00\u4e2a Web \u7248\u547d\u4ee4\u884c\u4e86\u3002<\/p>\n<\/div>\n<\/div>\n<p><strong>Docker \u652f\u6301<\/strong><\/p>\n<p>\u53e6\u5916 ttyd \u8fd8\u63d0\u4f9b\u4e86 Docker \u955c\u50cf\uff0c\u5982\u679c\u4f60\u4e0d\u60f3\u5b89\u88c5\u7684\u8bdd\uff0c\u53ef\u4ee5\u76f4\u63a5\u542f Docker\uff0c\u6bd4\u5982\u8fd9\u6837\u7684\u8bdd\u5c31\u53ef\u4ee5\u5728 7681 \u4e0a\u542f\u52a8\uff1a<\/p>\n<div class=\"hljs-cto code-style\">\n<div class=\"hljs-cto\">\n<pre class=\"has-pre-numbering\"><code class=\"language-\"><span>docker\u00a0run\u00a0-it\u00a0--rm\u00a0-p\u00a07681:7681\u00a0tsl0922\/ttyd\u00a0<\/span>\r\n<\/code><\/pre>\n<p>\u4f46\u8fd9\u5b9e\u9645\u4e0a\u662f\u628a\u5bb9\u5668\u5185\u90e8\u7684\u547d\u4ee4\u884c\u66b4\u9732\u51fa\u6765\u4e86\uff0c\u5982\u679c\u8981\u66b4\u9732\u5bbf\u4e3b\u673a\u7684\u547d\u4ee4\u884c\u8fd8\u9700\u8981 mount \u4e0b\u78c1\u76d8\uff1a<\/p>\n<\/div>\n<\/div>\n<p><strong>SSH \u7ec8\u7aef<\/strong><\/p>\n<p>ttyd \u8fd8\u652f\u6301 SSH \u7ec8\u7aef\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<div class=\"hljs-cto code-style\">\n<div class=\"hljs-cto\">\n<pre class=\"has-pre-numbering\"><code class=\"language-\"><span>ttyd\u00a0login\u00a0<\/span>\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u7684\u8bdd\uff0c\u6253\u5f00\u6d4f\u89c8\u5668\u4e4b\u540e\u5c31\u9700\u8981 SSH \u767b\u5f55\uff0c\u8f93\u5165\u6b63\u786e\u7684 SSH \u7528\u6237\u540d\u548c\u5bc6\u7801\u540e\u624d\u80fd\u4f7f\u7528\u3002<\/p>\n<\/div>\n<\/div>\n<p><strong>SSL \u652f\u6301<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u60f3\u914d\u7f6e SSL \u652f\u6301\uff0c\u5373\u652f\u6301 HTTPS \u7684\u8bdd\uff0c\u53ef\u4ee5\u81ea\u5df1\u751f\u6210\u8bc1\u4e66\u5e76\u6dfb\u52a0\u5bf9\u5e94\u7684\u53c2\u6570\u6765\u542f\u52a8 ttyd\uff0c\u53c2\u8003\u94fe\u63a5\u662f\uff1ahttps:\/\/github.com\/tsl0922\/ttyd\/wiki\/SSL-Usage\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ttyd\u662f\u4e00\u6b3e\u53ef\u4ee5\u5c06\u547d\u4ee4\u884c\u8f6c\u5230 Web \u6267\u884c\u7684\u5de5\u5177\uff0c\u57fa\u4e8e C \u7f16\u5199\u7684\u3002 https:\/\/github.com\/ [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[30],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-software-resources","tag-guthub"],"views":2515,"_links":{"self":[{"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":1,"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":359,"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions\/359"}],"wp:attachment":[{"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tyhlw.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}