Tuesday, November 18, 2014

Manage your Raspberry Pi with a shell session in a web browser -- Introducing ShellInABox

Raspberry Pi B+ top.jpg
Image Credit:" Raspberry Pi B+ top" by Lucasbosch - Own work. Licensed under CC BY-SA 3.0 via Wikimedia Commons
Sometimes you need to log into a Pi (Or any Linux system for that matter) and you do not have a SSH client installed on the machine you happen to be behind. I have built lots of Raspberry Pi based gizmos and sent them on their way to parts unknown. Using a little chunk of software called "shellinabox" you can use any modern web browser to get a shell session. No plugins, no Flash, no Java applets, no putty, no trying to find the terminal app on a mac. Just point your browser and login. Shellinabox is remarkably fully featured, supporting full VT terminal, colors, copy/paste clipboard, and more. Running VIM and other full screen applications work perfectly. This awesome software has had a long lineage, originally based on a Java Applet the creator Markus Gutschke recently rewrote it to only use javascript, css and AJAX. All standard in modern browsers.

Shellinabox is completely self contained and does all it's work over one port (tcp/4200 by default). It is also relatively light weight, using about 5MB of memory on my systems. The default configuration does exactly what you would expect, when you point a web browser at it it will ask you for a username and password and logs you in to a shell session. Under the hood there are a lot more capabilities. You can actually substitute any interactive program in place of the login shell.

Installing Shellinabox

If you happen to be running Raspbian this is going to be really easy. Shellinabox is a standard package. All we need to do is install it and optionally do some customization.

pi$ sudo apt-get install shellinabox

If you want to install from source code or just explore how Shellinabox works, visit http://code.google.com/p/shellinabox.

Customize Shellinabox

You can completely skip this section if you like the default look and feel. Personally black text on white background makes my eyes bleed, so below I will include the steps to customize the colors. I prefer black background, call me old school, but I like the CRT type experience for shell sessions. White on black is acceptable, green on black is preferable.

All configuration for Shellinabox happens in /etc/shellinabox and /etc/default/shellinabox. The color themes are all handled by regular CSS so they are easy to modify. Style sheets are stored in files under /etc/shellinabox/options-available and use filenames that define their precidance with a number. This determines the order in which they are interpreted and the underscore (_) or plus (+) determines if they are enabled by default. These files are then symlinked into /etc/shellinabox/options-enabled to make them available to the user. To give me green on black, I create a file /etc/shellinabox/options-available/00+Green On Black.css which contains:

#vt100 #cursor.bright {
  background-color: white;
  color:            black;

#vt100 #scrollable {
  color:            #00ff00;
  background-color: #000000;

#vt100 #scrollable.inverted {
  color:            #000000;
  background-color: #00ff00;

#vt100 .ansi15 {
  color:            #000000;

#vt100 .bgAnsi0 {
  background-color: #00ff00;

Then, I make the symlinks:

pi$ cd /etc/shellinabox/options-enabled
pi$ sudo rm -f 00*
pi$ sudo ln -s ../options-available/00+Green\ On\ Black.css  .
pi$ sudo /etc/init.d/shellinabox restart

This will leave you with:

ls -l 
total 4
lrwxrwxrwx 1 root root  42 Nov 18 12:10 00+Green On Black.css -> ../options-available/00+Green On Black.css
lrwxrwxrwx 1 root root  42 May  3  2012 01+Color Terminal.css -> ../options-available/01+Color Terminal.css
lrwxrwxrwx 1 root root  38 May  3  2012 01_Monochrome.css -> ../options-available/01_Monochrome.css
-rw-r--r-- 1 root root 189 May  3  2012 README


To connect to your Pi, aim your web browser at port 4200. Use the URL: http://nnn.nnn.nnn.nnn:4200/ where nnn.nnn.nnn.nnn is the IP address or hostname of your Raspberry Pi. You will likely be prompted with a SSL Certificate warning similar to the one below which is from Google Chrome. You can create real certificates for shellinabox, check the documentation if you want to. For now we will proceed by clicking the dialog as shown.

Once past the SSL warning you will be requested to login with a username and password. Do it. Once you are in, you are free to shell around to your hearts content.


Shellinabox is a great little tool to have in your toolbox. When you need to deploy a Raspberry Pi and might need to log in from a station that might not have a SSH client. Use them together, use them in peace.

Thanks for reading, Feedback to @sysmatt on twitter or comment below!

Like this article? Maybe you would like some of my other tutorials and articles: http://sysmatt.blogspot.com/