Brief: This guide features a nifty program called ttyd which allows you to share your Linux terminal over a web browser.
In this guide, we will demonstrate how to install ttyd on Linux using source tarball and snap tool.
Method 1: Install ttyd on Linux from the Sources
In this section, we will demonstrate the installation of ttyd on Ubuntu/Debian distributions.
First off, launch your terminal and update the package lists using the following apt command.
$ sudo apt update
Next, install the dependencies required to install ttyd as follows.
$ sudo apt-get install build-essential cmake git libjson-c-dev libwebsockets-dev
Ttyd is not officially hosted on Ubuntu’s repository or any other Linux distribution’s official repository for that matter. It is only available on GitHub.
As such we are going to clone the git repository as follows.
$ git clone https://github.com/tsl0922/ttyd.git
Once the git repository is cloned, navigate into the directory.
$ cd ttyd
Create a separate build directory and navigate into it.
$ mkdir build && cd build
Then run the cmake command to create CMakefiles within the directory
$ cmake ..
You can confirm the generation of the Cmakefiles by listing them as follows.
$ ls -l
Finally, build ttyd from the source.
$ sudo make && sudo make install
To confirm that ttyd was successfully installed, run the command
$ ttyd --version ttyd version 1.7.2-3225432
Method 2: Install Ttyd Using Snap Tool
Alternatively, you can install ttyd as a snap package as shown.
$ sudo snap install ttyd --classic
To start sharing your Linux terminal, run the following command where the
-p flag specifies the web port that ttyd will be listening on, in this case, port 8080
$ ttyd -p 8080 bash
You should get the following output on the terminal.
Next, head over to your web browser, and browse the following URL.
This opens a Linux terminal on the web browser as shown below. You can proceed to run commands as you would on any Linux terminal.
To access the terminal from a different Linux host, simply use the server’s IP address instead.
Secure Ttyd by Enabling HTTPS SSL Certificate
If you want to run ttyd on a secure HTTPS protocol, you need to obtain a free Let’s Encrypt SSL certificate for your domain by installing certbot via Snap, and then you can request a certificate for your domain as shown.
$ sudo apt install snapd $ sudo snap install core; sudo snap refresh core $ sudo snap install --classic certbot $ sudo ln -s /snap/bin/certbot /usr/bin/certbot $ certbot certonly -d <your domain>
You’ll now be able to run ttyd on HTTPS:
$ ttyd --ssl --ssl-cert /etc/letsencrypt/live/<your domain>/fullchain.pem --ssl-key /etc/letsencrypt/live/<your domain>/privkey.pem <command>
To get assistance with all the command line options run the ttyd command as follows.
$ ttyd --help
For more command usages of ttyd, visit the ttyd Wiki page.
This guide explored a handy tool called ttyd and how you can seamlessly share your Linux terminal over a web browser with other remote users. Your feedback is much welcome.