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 is 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
$ vim Dockerfile
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 3000ENTRYPOINT ["node"]
CMD ["app.js", "-p", "3000"]
  • 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
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
CMD ["app.js", "--sslkey", "key.pem", "--sslcert", "cert.pem", "-p", "3000"]
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
RUN echo 'term:yourpassword' | chpasswd
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 3000ENTRYPOINT ["node"]
CMD ["app.js", "--sslkey", "key.pem", "--sslcert", "cert.pem", "-p", "3000"]

Build Your Docker Image

$ sudo docker build -t yourusername/wetty .
$ 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.

Tips

To change the login timeout, edit file /etc/login.defs and look for LOGIN_TIMEOUT. (Reference)

References

Related