Sharing a Linux Terminal Over the Web

In the previous article, I wrote about tools for sharing terminals. Given the number of possibilities I found beyond tux  and screen , I was excited to look for tools that used the web because, typically, head nodes or workstations open ports 22 (SSH), 443 (HTTPS), and sometimes 80 or 8080 (HTTP). Can I find terminal-sharing tools that use these ports? Moreover, can a web browser be used for terminal sharing? For those not familiar with the command line, a web browser would help them get started – and perhaps even help them learn to use the command line.

I hate to say it, but I was a bit disappointed. I found several possible tools, but they were either dead projects or didn’t work. Only one tool met my requirements (which I discuss here), but if you know of more, please share that information.

I did find some tools that create links between systems over the web that would allow you to then use one of the tools from the previous article (e.g., tmux  or screen ), but these weren’t exactly the tools I was attempting to find. However, in the case that more information is useful, I'll cover those tools in this article as well.

tty-share

The only terminal-sharing tool I could find that used the web and web browsers was tty-share . It is easy to install by looking for the appropriate binary for the latest release or building it yourself. Fortunately, I could use the amd64  binary on my Ubuntu system without issues.

You can put the binary where you like. For example, I copied it to /usr/local/bin . To start tty-share  on the local system, you type the command:

$ tty-share --public

The terminal screen should look something like Figure 1, which shows your terminal going into a tty-share  session.

Figure 1: Terminal window on system 1 running the `tty-share --public` command.

You can then share the URL in the public session  line (second line) with another user on another system. When they paste that link into their web browser, they will get a command line, as shown in Figure 2, where they can then enter a statement, which will show up on system 1, as on system 2 (Figure 3), typo and all.

Figure 2: Web browser on system 2.
Figure 3: Terminal window on system 1 with command from system 2.

The two users can continue to type commands and see the output. Alternatively, the user who initiated the sharing session could use their browser with the localhost link (local session line) returned by the tty-share  command. If they do that, they should not end the session in the terminal or the entire sharing session would end.

If you decide to use the browser, the shared session will appear in the terminal, your browser, and the other user’s browser.

Because tty-share  is web based, you can even use it with Microsoft Windows. The Windows user just pastes the URL into their web browser, which then brings up a terminal window where they can type commands.

For example, a user on a Linux system starts tty-share  (Figure 4). The URL is shared with the Windows user who then pastes it in their browser. Figure 5 is a screenshot of the Brave browser on a Windows system after the user types a message, and Figure 6 shows the terminal window on the Linux system.

Figure 4: Terminal on the Linux system.
Figure 5: Terminal on the Windows system in the Brave browser.
Figure 6: Terminal on the Linux system with the same input and output as on the Windows terminal.

Terminal Multiplexers

The next two tools don’t provide terminal multiplexing over the web by themselves, but they can provide a web-based communication link between two systems, over which you could then run something like tmux  or screen .

ttyd

The t tyd  command-line tool lets you share your terminal output over the web. It is not a terminal-sharing tool that allows interaction between two users. Rather, the primary user runs commands, and the output is displayed to the other user, making it good for demos or learning. If you want true collaboration between users, you can run tmux  or screen  with ttyd .

The ttyd  tool uses the libwebsockets  library with the libuv  library for speed and the cross-platform Xterm.js for the terminal portion. The module runs on Linux, Windows, FreeBSD, OpenBSD, OpenWrt, and macOS.

The easiest way to install ttyd  on a Linux system is to build it. On an Ubuntu system, the instructions from the GitHub site were short and worked perfectly:

sudo apt-get install build-essential cmake git libjson-c-dev libwebsockets-dev
git clone https://github.com/tsl0922/ttyd.git
cd ttyd && mkdir build && cd build
cmake ..
make && sudo make install

I then copied the binary to /usr/local/bin .

To use ttyd  to share a terminal over the web, type:

$ ttyd -p 8080 bash

You should see something like Figure 7 (although you might not see all of the lines until you go to the corresponding URL).

Figure 7: Terminal after running ttyd.

Next, open a URL in your browser at http://localhost:8080 , and you should see something like Figure 8. To share your terminal, run tmux  or screen  as you would in a terminal.

Figure 8: Browser tab after running ttyd.

gotty

As with ttyd , you can use gotty  to establish a web-based connection, over which tmux  or screen  can run. As you can guess from the name, it is written in Go. An example of a gotty  command for sharing a terminal is:

$ gotty tmux new -A -s gotty bash

This command starts a new tmux  Bash session. You share it as you would a tmux  session, as discussed in the previous article.

Summary

The previous article illustrated how to share a terminal with the use of one of several tools. While reviewing some of the lesser known tools in the last article, I thought that someone must have developed the same terminal-sharing capability over the web in a web browser. Because many systems will leave one of the web ports open, sharing a terminal through the web should be obvious and easy.

Given the open source world, I’ve become used to finding more than one project that scratches my itch. However, in this case, I only found one tool that met my goal; however, that is all it takes. The tty-share  tool allows me to generate a sharable URL that a user can paste into a web browser that starts a sharing terminal. I found tty-share  very easy to use, and I highly recommend it for sharing a terminal over the web.

Related content

  • Sharing Linux Terminals

    Sometimes sharing a screen between two users is enormously helpful. We look at two terminal sharing tools: screen and tmux.

  • New features in Windows Terminal Preview
    Windows Terminal Preview comes with interesting new features, such as state-preserving quick windows access via shortcuts and configuration of almost all settings in a GUI, which is reason enough to take a look at the preview.
  • Command-line tools for the HPC administrator
    Several sophisticated command-line tools can help you manage and troubleshoot HPC (or other) systems.
  • MobaXterm: Unix for Windows

    MobaXterm, a portable X server for Windows, bundles built-in Unix/Posix tools into a single portable EXE file, letting you use a Linux command line and tools on the Windows desktop.

  • Redo Backup
    Redo Backup backs up complete hard drives locally or over a network. The focus is on simple operation and high reliability in a variety of deployment scenarios.
comments powered by Disqus