Home Debian ttyd – Share Your Linux Terminal Over Web Browser

ttyd – Share Your Linux Terminal Over Web Browser

Brief: This guide features a nifty program called ttyd which allows you to share your Linux terminal over a web browser.

Ttyd is a simple command-line utility used for sharing your Linux terminal over a web browser. It is a cross-platform and fully-featured terminal built on top of libuv and WebGL2 Javascript API for performance and SSL support based on OpenSSL.

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
Clone Git Ttyd Repository
Clone Git Ttyd Repository

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 ..
Create CMakefiles
Create CMakefiles

You can confirm the generation of the Cmakefiles by listing them as follows.

$ ls -l
Verify CMakefiles
Verify CMakefiles

Finally, build ttyd from the source.

$ sudo make && sudo make install
Build Ttyd from Source
Build Ttyd from Source

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

How To Use Ttyd to Share Linux Terminal Over Web Browser

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.

Start Ttyd to Share Linux Terminal
Start Ttyd to Share Linux Terminal

Next, head over to your web browser, and browse the following URL.

http://localhost:8080

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.

Running Linux Terminal Over Browser
Running Linux Terminal Over Browser

To access the terminal from a different Linux host, simply use the server’s IP address instead.

http://server-ip-address:8080
Access Remote Linux Terminal Over Browser
Access Remote Linux Terminal Over Browser

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.

Conclusion

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.

Winnie Ondara
My name is Winnie, a Linux enthusiast and passionate tech writer in Linux and DevOPs topics. I enjoy keeping abreast with the latest technologies in the Linux ecosystem and trying out new tools provided by the FOSS community.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.