Setup Web Terminal using Wetty Docker Image

Introduction

SSH is the way to connect and command your Linux machine. Doing this from Windows is even more painful as you need a client like Putty installed (Or enable built-in SSH if you’re using Windows 10).

What if you can do it right from your web browser from any OS without installing anything!?!

What is Wetty?

Wetty = Web + tty.
Terminal over HTTP and HTTPS. Wetty uses ChromeOS’ terminal emulator (hterm) which is a full fledged implementation of terminal emulation written entirely in Javascript. Also it uses websockets instead of Ajax and hence better response time.

Source: https://github.com/krishnasrinivas/wetty

Prerequisite

  • Ubuntu Server with Docker installed (See this blog on how to get one on Azure)

Installation

  1. Clone Wetty repository on GitHub.
$ git clone git@github.com:krishnasrinivas/wetty.git

2. Edit Dockerfile

$ vim Dockerfile

You will see the something like this:

FROM node:0.10.38
MAINTAINER Nathan LeClaire <nathan@docker.com>
ADD . /app
WORKDIR /app
RUN npm install
RUN apt-get update
RUN apt-get install -y vim
RUN useradd -d /home/term -m -s /bin/bash term
RUN echo 'term:term' | chpasswd
EXPOSE 3000
ENTRYPOINT ["node"]
CMD ["app.js", "-p", "3000"]

This tells us that:

  • Wetty is a Node.js application.
  • It creates a new user term which we can use to logon.
  • The web interface is exposed at port 3000

Setup HTTPS — Always use HTTPS!

3. If you don’t have SSL certificates from a CA you can
create a self signed certificate using this command:

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

You need to fill in some information. Better to put common name with your domain name you want to publish your web terminal e.g. terminal.yourdomain.com

Country Name (2 letter code) [AU]:TH
State or Province Name (full name) [Some-State]:Bangkok
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Demo Company
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:terminal.yourdomain.com
Email Address []:admin@yourdomain.com

4. Update entry point in Dockerfile to include certificates.

CMD ["app.js", "--sslkey", "key.pem", "--sslcert", "cert.pem", "-p", "3000"]

5. Copy private key id_rsa you normally use to connect to your Ubuntu server and add these lines to Dockerfile.

RUN mkdir /home/term/.ssh
COPY id_rsa /home/term/.ssh/id_rsa
RUN chmod 600 /home/term/.ssh/id_rsa && chown -Rf term /home/term/.ssh

6. Update password as you wish.

RUN echo 'term:yourpassword' | chpasswd

At the end, you Dockerfile may look like this:

FROM node:0.10.38
MAINTAINER admin@yourdomain.com
ADD . /app
WORKDIR /app
RUN npm install
RUN apt-get update
RUN apt-get install -y vim
RUN useradd -d /home/term -m -s /bin/bash term
RUN echo 'term:yourpassword' | chpasswd
RUN mkdir /home/term/.ssh
COPY id_rsa /home/term/.ssh/id_rsa
RUN chmod 600 /home/term/.ssh/id_rsa && chown -Rf term /home/term/.ssh
EXPOSE 3000
ENTRYPOINT ["node"]
CMD ["app.js", "--sslkey", "key.pem", "--sslcert", "cert.pem", "-p", "3000"]

Build Your Docker Image

$ sudo docker build -t yourusername/wetty .

Wait until it finishes, like this:

$ sudo docker build -t demo/wetty .
Sending build context to Docker daemon 1.042MB
Step 1/15 : FROM node:0.10.38
---> 82073591bd0c
Step 2/15 : MAINTAINER admin@yourdomain.com
---> Using cache
---> 067a8d078ccb
Step 3/15 : ADD . /app
---> ccd418e158ee
Step 4/15 : WORKDIR /app
Removing intermediate container 514c8c3f5511
---> d8611af96ced
Step 5/15 : RUN npm install
---> Running in e635ea2d39be
.
.
.
Step 13/15 : EXPOSE 3000
---> Running in f246b51e0a0f
Removing intermediate container f246b51e0a0f
---> 39b74e2eda59
Step 14/15 : ENTRYPOINT ["node"]
---> Running in 4fa38e6c2d19
Removing intermediate container 4fa38e6c2d19
---> ee6c549f88ca
Step 15/15 : CMD ["app.js", "--sslkey", "key.pem", "--sslcert", "cert.pem", "-p", "3000"]
---> Running in 26c1f3817918
Removing intermediate container 26c1f3817918
---> f69d767e6c92
Successfully built f69d767e6c92
Successfully tagged demo/wetty:latest

Spin Up a Container

$ sudo docker run --name termdemo -p 3000:3000 -dt demo/wetty

Test Your Wetty

Go to your domain e.g. https://terminal.yourdomain.com:3000 and log in with id term and its password.

Then, try SSH to your Ubuntu host.


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.