GoTTY, share the terminal as a web application

about GoTTY

In the next article we are going to take a look at GoTTY. It is a program that allows users to share applications to the Gnu / Linux terminal via a web browser. GoTTY is a simple web server written in Go that runs a non-GUI program, and can be launched in such a way that a browser can display it and optionally allows the user to interact.

Perhaps not everyone will find the possibility of run a specific command line program in a browser window. But there are some cases, such as when we want to monitor a system remotely using top without having to connect to the system, in which it may be interesting to have this possibility.

If we can get the output of top to display in a browser window, this would be a very simple solution. Although there are other options to obtain the same result, we may be interested in having other features of the command line, or having the option of using authenticated users to interact with the software that is running. This and other things, GoTTY will allow us to do it easily.

about transfer.sh
Related article:
Transfer.sh, share files easily from the terminal

GoTTY installation on Ubuntu

In order to use GoTTY we will need to have Go installed. Most of the Gnu / Linux distributions have the Go language in the official repository, so we can install it easily. To install and configure it in our Ubuntu, a while ago we wrote in this blog a article in which it is explained how to do it in a simple way.

We will also need to install git, which we can do by typing in the terminal (Ctrl + Alt + T):

sudo apt install git

When we already have Go we can start writing the following. This command will install the GoTTY binary in your environment variable:

go get github.com/yudai/gotty

To check that everything has been correct, write the following command:

GoTTY installation check

ls $GOPATH/bin/

How to use GoTTY in Ubuntu

To execute it, we will use the following syntax:

$GOBIN/gotty [opciones] <comando>

In case it doesn't matter launch and share top command, you just have to write:

running top with GoTTY

$GOBIN/gotty top

The top command will run on your current machine at port 8080 (http://127.0.0.1:8080/). From the browser you will not see a static image, the screen is updated as if it were running in a terminal.

gotty top running in browser

The server will run until you kill it. This is accomplished by pressing Ctrl + C. If someone is connected to the server, it will take two presses of Ctrl + C. To this command you can add options to change the port (-p) and the address (-a).

Keep in mind that by default, GoTTY does not allow clients to write entries to the TTY, it only allows you to change the size of the windows.

Edit a file from the browser

We will be able use the -wo –permit-write option to allow clients to write to the TTY, which it's not recommended due to possible security threats on the server.

The following command will use the vi command line editor to open the file ubunlog.txt and will allow you to edit it from the web browser:

Gotty editing file

$GOBIN/gotty -w vi ubunlog.txt

Use GoTTY with basic authentication (username and password)

In the first case we just looked at, we probably don't care much if strangers can see the top output. If the machine GoTTY is running on is behind a firewall, outsiders won't be able to see it. For some applications, that would be sufficient. But, if for example, if we allow entry (with the -w option), people could kill processes remotely, and this is probably not a good idea to post on the web.

To try to put a kind of solution to this, we can activate a basic authentication system. Here clients will need to enter the specified username and password to connect to the GoTTY server.

The following command will restrict client access using the -c option and will prompt users for the specified credentials. For this example the username will be ubunlog and the password @12345.

username and password with GoTTY

$GOBIN/gotty -w -p "9000" -c "ubunlog:@12345" top

Generate Random URL in Gotty

allegatory url generated with GoTTY

Another way to restrict server access is using the -r option. Here, GoTTY will generate a random URL so that only users who know it can access the server.

The ones we just saw are just some of the things that can be done with GoTTY. They can consult these and others, in more detail from the project GitHub page. This is one of those solutions that is not for everything, but if you need what it does, it is good to have this possibility available.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.