{"id":9504,"date":"2019-02-10T07:36:02","date_gmt":"2019-02-10T07:36:02","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=9504"},"modified":"2019-02-10T07:36:02","modified_gmt":"2019-02-10T07:36:02","slug":"gotty-share-your-linux-terminal-tty-as-a-web-application","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/02\/10\/gotty-share-your-linux-terminal-tty-as-a-web-application\/","title":{"rendered":"GoTTY \u2013 Share Your Linux Terminal (TTY) as a Web Application"},"content":{"rendered":"<p><strong>GoTTY<\/strong>\u00a0is a simple GoLang based command line tool that enables you to share your terminal(TTY) as a web application. It turns command line tools into web applications.<\/p>\n<p>It employs Chrome OS\u2019 terminal emulator (<strong>hterm<\/strong>) to execute a JavaScript based terminal on a web browsers. And importantly,\u00a0<strong>GoTTY<\/strong>\u00a0runs a web socket server that basically transfers output from the\u00a0<strong>TTY<\/strong>\u00a0to clients and receives input from clients (that is if input from clients is permitted) and forwards it to the\u00a0<strong>TTY<\/strong>.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/teleconsole-share-linux-terminal-session-with-friends\/\" target=\"_blank\" rel=\"noopener\">Teleconsole \u2013 Share Your Linux Terminal with Your Friends<\/a><\/p>\n<p>Its architecture (hterm + web socket idea) was inspired by\u00a0<a href=\"https:\/\/www.tecmint.com\/access-linux-server-terminal-in-web-browser-using-wetty\/\" target=\"_blank\" rel=\"noopener\"><strong>Wetty program<\/strong><\/a>\u00a0which enables terminal over\u00a0<strong>HTTP<\/strong>and\u00a0<strong>HTTPS<\/strong>.<\/p>\n<h4>Prerequisites:<\/h4>\n<p>You should have\u00a0<a href=\"https:\/\/www.tecmint.com\/install-go-in-linux\/\" target=\"_blank\" rel=\"noopener\">GoLang (Go Programming Language)<\/a>\u00a0environment installed in Linux to run GoTTY.<\/p>\n<h3>How To Install GoTTY in Linux Systems<\/h3>\n<p>If you already have a\u00a0<a href=\"https:\/\/www.tecmint.com\/install-go-in-linux\/\" target=\"_blank\" rel=\"noopener\">working GoLang environment<\/a>, run the\u00a0<strong>go get<\/strong>\u00a0command below to install it:<\/p>\n<pre># go get github.com\/yudai\/gotty\r\n<\/pre>\n<p>The command above will install the\u00a0<strong>GoTTY<\/strong>\u00a0binary in your\u00a0<strong>GOBIN<\/strong>\u00a0environment variable, try to check if that is the case:<\/p>\n<pre># ls $GOPATH\/bin\/\r\n<\/pre>\n<div id=\"attachment_25008\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Check-Go-Environment.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25008\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Check-Go-Environment.png\" alt=\"Check GOBIN Environment\" width=\"342\" height=\"59\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check GOBIN Environment<\/p>\n<\/div>\n<h3>How To Use GoTTY in Linux<\/h3>\n<p>To run it, you can use the\u00a0<strong>GOBIN env<\/strong>\u00a0variable and command auto-completion feature as follows:<\/p>\n<pre># $GOBIN\/gotty\r\n<\/pre>\n<p>Else, run GoTTY or any other Go program without typing the full path to the binary, add your GOBIN variable to PATH in the\u00a0<code>~\/.profile<\/code>\u00a0file using the\u00a0<strong>export<\/strong>\u00a0command below:<\/p>\n<pre>export PATH=\"$PATH:$GOBIN\"\r\n<\/pre>\n<p>Save the file and close it. Then source the file to effect the changes above:<\/p>\n<pre># source ~\/.profile\r\n<\/pre>\n<p>The general syntax for running GoTTY commands is:<\/p>\n<pre>Usage: gotty [options] &lt;Linux command here&gt; [&lt;arguments...&gt;]\r\n<\/pre>\n<p>Now run GoTTY with any command such as the\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-check-disk-space-in-linux\/\" target=\"_blank\" rel=\"noopener\">df command<\/a>\u00a0to view system disk partitions space and usage from the web browser:<\/p>\n<pre># gotty df -h\r\n<\/pre>\n<p>GoTTY will start a web server at port\u00a0<strong>8080<\/strong>\u00a0by default. Then open the URL:\u00a0<code>http:\/\/127.0.0.1:8080\/<\/code>\u00a0on your web browser and you will see the running command as if it were running on your terminal:<\/p>\n<div id=\"attachment_25009\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-Linux-Disk-Usage.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25009\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-Linux-Disk-Usage.png\" alt=\"Gotty Linux Disk Usage\" width=\"749\" height=\"639\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Gotty Linux Disk Usage<\/p>\n<\/div>\n<h3>How To Customize GoTTY in Linux<\/h3>\n<p>You can alter default options and your terminal (<strong>hterm<\/strong>) in the profile file\u00a0<code>~\/.gotty<\/code>, it will load this file by default in case it exists.<\/p>\n<p>This is the main customization file read by gotty commands, so, create it as follows:<\/p>\n<pre># touch ~\/.gotty\r\n<\/pre>\n<p>And set your own valid values for the config options (find all config options here) to customize GoTTY for example:<\/p>\n<pre>\/\/ Listen at port 9000 by default\r\nport = \"9000\"\r\n\r\n\/\/ Enable TSL\/SSL by default\r\nenable_tls = true\r\n\r\n\/\/ hterm preferences\r\n\/\/ Smaller font and a little bit bluer background color\r\npreferences {\r\n    font_size = 5,\r\n    background_color = \"rgb(16, 16, 32)\"\r\n}\r\n<\/pre>\n<div class=\"google-auto-placed ap_container\">\n<p>You can set your own\u00a0<strong>index.html<\/strong>\u00a0file using the\u00a0<code>--index<\/code>\u00a0option from the command line:<\/p>\n<pre># gotty --index \/path\/to\/index.html uptime\r\n<\/pre>\n<h3>How to Use Security Features in GoTTY<\/h3>\n<p>Because\u00a0<strong>GoTTY<\/strong>\u00a0doesn\u2019t offer reliable security by default, you need to manually use certain security features explained below.<\/p>\n<h4>Permit Clients to Run Commands\/Type Input in Terminal<\/h4>\n<p>Note that, by default, GoTTY doesn\u2019t permit clients to type input into the TTY, it only enables window resizing.<\/p>\n<p>However, you can use the\u00a0<code>-w<\/code>\u00a0or\u00a0<code>--permit-write<\/code>\u00a0option to allow clients to write to the TTY, which is not recommended due to security threats to the server.<\/p>\n<p>The following command will use\u00a0<a href=\"https:\/\/www.tecmint.com\/vi-editor-usage\/\" target=\"_blank\" rel=\"noopener\">vi command line editor<\/a>\u00a0to open the file\u00a0<strong>fossmint.txt<\/strong>\u00a0for editing in the web browser:<\/p>\n<pre># gotty -w vi fossmint.txt\r\n<\/pre>\n<p>Below is the vi interface as seen from the web browser (use vi commands here as usual):<\/p>\n<div id=\"attachment_25011\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-Web-Vi-Editor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25011\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-Web-Vi-Editor.png\" alt=\"Gotty Web Vi Editor\" width=\"749\" height=\"363\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Gotty Web Vi Editor<\/p>\n<\/div>\n<h4>Use GoTTY with Basic (Username and Password) Authentication<\/h4>\n<p>Try to activate a basic authentication mechanism, where clients will be required to input the specified username and password to connect to the GoTTY server.<\/p>\n<p>The command below will restrict client access using the\u00a0<code>-c<\/code>\u00a0option to ask users for specified credentials (username:\u00a0<strong>test<\/strong>\u00a0and password:\u00a0<strong>@67890<\/strong>):<\/p>\n<pre># gotty -w -p \"9000\" -c \"test:@67890\" glances\r\n<\/pre>\n<div id=\"attachment_25012\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-use-basic-authentication.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25012\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-use-basic-authentication.png\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-use-basic-authentication.png 811w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-use-basic-authentication-768x587.png 768w\" alt=\"Gotty with Basic Authentication\" width=\"811\" height=\"620\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Gotty with Basic Authentication<\/p>\n<\/div>\n<h4>Gotty Generate Random URL<\/h4>\n<p>Another way of restricting access to the server is by using the\u00a0<code>-r<\/code>\u00a0option. Here, GoTTY will generate a random URL so that only users who know the URL can get access to the server.<\/p>\n<p>Also use the\u00a0<strong>\u2013title-format \u201cGoTTY \u2013 {{ .Command }} ({{ .Hostname }})<\/strong>\u201d option to define the web browsers interface title and\u00a0<a href=\"https:\/\/www.tecmint.com\/glances-an-advanced-real-time-system-monitoring-tool-for-linux\/\" target=\"_blank\" rel=\"noopener\">glances command<\/a>\u00a0is used to show system monitoring stats:<\/p>\n<pre># gotty -r --title-format \"GoTTY - {{ .Command }} ({{ .Hostname }})\" glances\r\n<\/pre>\n<p>The following is result of the command above as seen from the web browser interface:<\/p>\n<div id=\"attachment_25013\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-Random-URL-for-Glances-Linux-Monitoring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25013\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-Random-URL-for-Glances-Linux-Monitoring.png\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-Random-URL-for-Glances-Linux-Monitoring.png 811w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Gotty-Random-URL-for-Glances-Linux-Monitoring-768x503.png 768w\" alt=\"Gotty Random URL for Glances Linux Monitoring\" width=\"811\" height=\"531\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Gotty Random URL for Glances Linux Monitoring<\/p>\n<\/div>\n<h4>Use GoTTY with SSL\/TLS<\/h4>\n<p>Because by default, all connections between the server and clients are not encrypted, when you send secret information through GoTTY such as user credentials or any other info, you have to use the\u00a0<code>-t<\/code>\u00a0or\u00a0<code>--tls<\/code>\u00a0option which enables TLS\/SSL on the session:<\/p>\n<p>GoTTY will by default read the certificate file\u00a0<code>~\/.gotty.crt<\/code>\u00a0and key file\u00a0<code>~\/.gotty.key<\/code>, therefore, start by creating a self-signed certification as well as the key file using the\u00a0<strong>openssl<\/strong>\u00a0command below (answer the question asked in order to generate the cert and key files):<\/p>\n<pre># openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ~\/.gotty.key -out ~\/.gotty.crt\r\n<\/pre>\n<p>Then use GoTTY in a secure way with SSL\/TLS enabled as follows:<\/p>\n<pre># gotty -tr --title-format \"GoTTY - {{ .Command }} ({{ .Hostname }})\" glances\r\n<\/pre>\n<h4>Share Your Terminal With Multiple Clients<\/h4>\n<p>You can make use of\u00a0<a href=\"https:\/\/www.tecmint.com\/tmux-to-access-multiple-linux-terminals-inside-a-single-console\/\" target=\"_blank\" rel=\"noopener\">terminal multiplexers<\/a>\u00a0for sharing a single process with multiple clients, the following command will start a new\u00a0<a href=\"https:\/\/www.tecmint.com\/tmux-to-access-multiple-linux-terminals-inside-a-single-console\/\" target=\"_blank\" rel=\"noopener\">tmux session<\/a>\u00a0named gotty with\u00a0<a href=\"https:\/\/www.tecmint.com\/glances-an-advanced-real-time-system-monitoring-tool-for-linux\/\" target=\"_blank\" rel=\"noopener\">glances command<\/a>\u00a0(make sure you have tmux installed):<\/p>\n<pre># gotty tmux new -A -s gotty glances \r\n<\/pre>\n<p>To read a different config file, use the\u00a0<strong>\u2013config \u201c\/path\/to\/file<\/strong>\u201d option like so:<\/p>\n<pre># gotty -tr --config \"~\/gotty_new_config\" --title-format \"GoTTY - {{ .Command }} ({{ .Hostname }})\" glances\r\n<\/pre>\n<p>To display the GoTTY version, run the command:<\/p>\n<pre># gotty -v \r\n<\/pre>\n<p>Visit the GoTTY GitHub repository to find more usage examples:\u00a0<a href=\"https:\/\/github.com\/yudai\/gotty\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/yudai\/gotty<\/a><\/p>\n<p>That\u2019s all! Have you tried it out? How do you find GoTTY?<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>GoTTY\u00a0is a simple GoLang based command line tool that enables you to share your terminal(TTY) as a web application. It turns command line tools into web applications. It employs Chrome OS\u2019 terminal emulator (hterm) to execute a JavaScript based terminal on a web browsers. And importantly,\u00a0GoTTY\u00a0runs a web socket server that basically transfers output from &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/02\/10\/gotty-share-your-linux-terminal-tty-as-a-web-application\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;GoTTY \u2013 Share Your Linux Terminal (TTY) as a Web Application&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9504","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/9504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=9504"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/9504\/revisions"}],"predecessor-version":[{"id":9507,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/9504\/revisions\/9507"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=9504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=9504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=9504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}