How to share your terminal over the web on Ubuntu 22.04

Endrit Qerreti

Endrit Qerreti

ttyd is a command line app that allows you to share your terminal online.

Let's say you want to show something on your terminal to your coworker, instead of recording your desktop and sending a video of your terminal, you can easily send the IP from where your coworker is able to see your terminal in real time.

Sharing your terminal over the web, means being able to access and work on your terminal through your web browser.

In this tutorial, you will learn how to share your terminal over the web on Ubuntu 22.04

Install ttyd on Ubuntu 22.04

Step 1 - Update your Ubuntu machine

First thing that you should do before installing ttyd, is to update your Ubuntu system. To update ubuntu, you can use apt package manager

sudo apt update -y

Step 2 - Install Dependencies

In order to be able to install and run ttyd without issues, you need to make sure you have the required dependencies installed on your system.

To install these dependencies, simply run the command below

sudo apt-get install -y build-essential cmake git libjson-c-dev libwebsockets-dev

Step 3 - Clone ttyd repository

Once you have updated your system, and installed the required dependencies, you can proceed to clone ttyd repository on your machine.

Clone tty repository by using the git command below

git clone https://github.com/tsl0922/ttyd.git

Step 4 - Install ttyd

Now you can proceed to build ttyd project. To do this, first you need to navigate to ttyd repository that you downloaded on the step above

cd ttyd

Next, create the build directory inside the ttyd directory

mkdir build

After creating the build folder , change directory to it

cd build

Now build the project

cmake ..

Once the building has been completed, you can now install ttyd using make command

make && sudo make install

Share your terminal

To share your terminal with ttyd is very simple.

By default ttyd uses port 7681, however, you can use any port you want. To set a custom port you need to use the -p argument and set your own port number

For example, to share your terminal using the default port 7681, run the command below

ttyd -p 7681 bash 

If you want to use a random port, then you need to use port 0

ttyd -p 0 bash

Your terminal will be shared on your IP, if you don't know your IP, you can easily find it with ip a command

ip a

To access your terminal, launch your browser and go to 127.0.0.1:7681

Protect your shared terminal

ttyd also allows you to protect your shared terminal with a username and password, meaning that anyone who want to access your terminal will need a username and password in order to do so.

Protecting your terminal is necessary when you install ttyd on a server with public IP

To share terminal using credentials, simply run the command below

ttyd -c username:password -p 7681 bash

Replace : username and password with your credentials

Now when you try to access your terminal, you will be prompted to login with the credentials that you specified

Make shared terminal writable

ttyd uses the readonly mode by default when sharing the terminal, which means you can only view the terminal but not run commands on it.

If you want to be able to run commands on your shared terminal from your browser, you can do so by using the writable option

ttyd -W -p 7681 bash

Conclusion

In this tutorial, you learned how to share your terminal over the web on Ubuntu 22.04.