How to Access Linux Server Terminal in Web Browser Using ‘Wetty (Web + tty)’ Tool

As a system administrator, you probably connect to remote servers using a program such as GNOME Terminal (or the like) if you’re on a Linux desktop, or a SSH client such as Putty if you have a Windows machine, while you perform other tasks like browsing the web or checking your email.

Linux Terminal Access in Browser

Wetty – Linux Terminal Access in Browser

Wouldn’t it be fantastic if there was a way to access a remote Linux server directly from the web browser? Luckily for us all, there is a tool called Wetty (Web + tty) that allows us to do just that – without the need to switch programs and all from the same web browser window.

Installing Wetty in CentOS 7 and Debian 8

Wetty is available from the GitHub repository of its developer. For that reason, regardless of the distribution you’re using some dependencies must be installed first manually before cloning the repository locally and installing the program.

In Fedora-based distros (in CentOS 7 and RHEL 7, the EPEL repository must be enabled first):

# yum update && yum install epel-release git nodejs npm

In Debian and its derivatives, the version of NodeJS available from the distribution’s repositories as of September 2015 (0.10.29) is older than the minimum version required to install Wetty (0.10.31), so you have to install it from the NodeJS GitHub developer repository:

# aptitude install curl
# curl --silent --location https://deb.nodesource.com/setup_0.12 | bash -
# aptitude update && aptitude install -y git nodejs npm

After installing these dependencies, clone the GitHub repository:

# git clone https://github.com/krishnasrinivas/wetty
Wetty Terminal Access Web

Clone Wetty – A Terminal Access Web

Change the working directory to wetty, as indicated in the message above:

# cd wetty

then install Wetty by running:

# npm install

If you get any error messages during the installation process, please address them before proceeding further. In my case, the need for a newer version of NodeJS in Debian was an issue that had to be solved before running npm install successfully.

Starting Wetty and Access Linux Terminal from Web Browser

At this point, you could start the web interface in local port 8080 for Wetty by running (this assumes your current working directory is /wetty):

# node app.js -p 8080

As you can see in the image below:

Access Wetty Linux Terminal from Web

Access Wetty Linux Terminal from Web

But do yourself a favor and DO NOT enter your username and password since this connection is not secure and you don’t want your credentials to travel through the wire unprotected.

For that reason, you should always run Wetty through HTTPS. Let’s create a self-signed certificate to secure our connection to the remote server:

# openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes

And then use it to launch Wetty via HTTPS.

Please note that you will need to open the custom HTTPS port where you will want to run Wetty:

# firewall-cmd --add-service=https # Run Wetty in the standard HTTPS port (443)
# firewall-cmd --permanent --add-service=https
# firewall-cmd --add-port=XXXX/tcp # Run Wetty on TCP port XXXX
# nohup node app.js --sslkey key.pem --sslcert cert.pem -p 8080 &

The last command in the above sequence will start Wetty in the background listening on port 8080. Since we are using a self-signed certificate, it is to be expected that the browser will show a security warning – It is perfectly safe to ignore it and add a security exception – either permanently or for the current session:

Wetty - SSL Security Warning

Wetty – SSL Security Warning

After you have confirmed the security exception you will be able to login to your VPS using Wetty. It goes without saying that you can run all commands and programs as if you were sitting in front of a real or virtual terminal, as you can see in the following screen cast:

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

12 Responses

  1. yashar esmaildokht says:

    shellinabox is like a wetty for connect ssh in web browser.

  2. Alan says:

    Having issues getting this working on a Linux Mint distro (17.3)

    I install dependencies, type “node app.js -p 8080” but I get this:
    —————————————————————————————————-

    module.js:338
    throw err;
    ^
    Error: Cannot find module ‘bytes’
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object. (/home/alan/wetty/node_modules/express/node_modules/connect/lib/utils.js:394:22)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

    —————————————————————————————————————————————-
    Not sure where to go from there. I’m an amateur when it comes to Linux, so I don’t know how to resolve this.

    • @Alan,
      If you followed the installation instructions at the top of this post, you must have installed npm. You can verify this by running
      dpkg -l | grep npm
      or
      which npm
      If npm is installed (as it should), the first command should return the actual package name, whereas the output of the second command will show the path to the executable file. Otherwise, install npm first following the instructions given here.
      Next, install the bytes module:
      sudo npm install bytes
      Then try again and let us know how it went.

      • Alan says:

        OK, after I enter “node app.js -p 8080” I’m getting this:

        ————————————————————————————————————–
        module.js:338
        throw err;
        ^
        Error: Cannot find module ‘serve-static’
        at Function.Module._resolveFilename (module.js:336:15)
        at Function.Module._load (module.js:278:25)
        at Module.require (module.js:365:17)
        at require (module.js:384:17)
        at Object. (/home/alan/wetty/node_modules/express/node_modules/connect/lib/middleware/static.js:19:18)
        at Module._compile (module.js:460:26)
        at Object.Module._extensions..js (module.js:478:10)
        at Module.load (module.js:355:32)
        at Function.Module._load (module.js:310:12)
        at Module.require (module.js:365:17)
        _________________________________________________________________

        Seems like I’m closing in on it, the errors are getting shorter.

        Sorry to be a pain, I do appreciate the help.

        • Ravi Saive says:

          @Alan,

          I am not familiar with Wetty, but still I think the server-static module is missing and you need to install through npm as shown:

          # npm install serve-static
          

          Let me know after you installing the above module, are you able to execute node app.js -p 8080 command?

          • Alan says:

            There was another NPM module that it complained about missing too. Did some Googling and found the NPM website, and looked at the services it needed. Did NPM installs on those items, then it worked.

            Between the help here, and doing some brainstorming, I’m figuring out how to make things work.

            Now, if I could just figure out how to have Wetty start on a reboot, I’d be good. Right now, I have to login to the machine, start the service, and then I can access it with a web browser. The terminal I opened to add the command has to stay open, though, which kind of defeats the purpose.

            I don’t really need a secure connection for it; the port isn’t available to the outside, so I just want to have it start on regular HTTP, not HTTPS.

            Wanted to be able to access it from inside my home network with my cellphone, but for some reason, it doesn’t pop up the keyboard on my phone after I connect(I see the login prompt, but my phone’s browser doesn’t recognize that it needs keyboard input). I haven’t tried my Android tablet, but I suspect it will have the same result.. Not sure how to resolve that, but I’ll try to figure it out.

            Of course, if I could find a terminal application for my Android phone that actually allows me to SSH into Linux boxes on my home network, that might even eliminate the need for Wetty for anything other than the Windows box.

            Thank you again to everyone that has helped. I am an amateur at this, and it’s a learning curve, but I’m enjoying learning Linux.

        • @Alan,
          I am replying to this comment because I didn’t find the Reply link on the one below. If you’re still looking for an application that allows you to SSH into your Linux servers using your Android phone, I’d highly recommend JuiceSSH (https://juicessh.com/). I’ve used it in a production environment and gets the job done pretty well. Hope it helps.

  3. Jalal Hajigholamali says:

    Hi,
    Thanks for nice article

  4. Ivaylo says:

    Trying to identify whether there is an option to leverage certificates with Wetty so that the connection will be based on public / private key pairs.

    • @Ivaylo,
      As Wetty works over a web connection, I would say it’s best to go with the certificates (you may want to consider using one signed from a CA if you don’t want your users to run into the “This connection is not trusted” message). Otherwise, feel free to check the GitHub repository for further ideas on how to use Wetty. You may even suggest this option be included in future releases of the program.

Leave a Reply to Ivaylo Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.