In this tutorial we shall see how to install Shellinabox (Pronounced as “Shell In A Box”) for remote access to Linux SSH terminal using AJAX/JavaScript and CSS enabled web browsers. Assuming that your Linux server is enabled with Firewall and allows only necessary ports (says HTTP(s)), then Shellinabox is an ideal solution to provide web based Shell terminal to users.
Installing Shellinabox on Linux
By default, Shellinabox package is included in all Linux distribution repositories including Debian, Ubuntu and CentOS. Make sure that your repository is enabled and available to install shellinabox.
On Debian and Ubuntu
root@ubuntu:~# apt-cache search shellinabox shellinabox - publish command line shell through AJAX interface root@ubuntu:~#
root@ubuntu:~# apt-get install shellinabox Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: shellinabox .... .... Setting up shellinabox (2.14-1) ... Processing triggers for ureadahead (0.100.0-16) ... root@ubuntu:~#
On RHEL, CentOS and Fedora
Configure yum repository on RedHat based distributions. Next you need to configure EPEL Repository:
How to enable EPEL Repo:
For EL5:
[root@centos export]# rpm -Uvh http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
For EL6:
[root@centos export]# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
For EL7:
[root@centos export]# rpm -Uvh http://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Then install shellinabox using the following yum command.
#yum install shellinabox Loaded plugins: security Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package shellinabox.x86_64 0:2.14-27.git88822c1.el5 set to be updated --> Finished Dependency Resolution .... .... .... Complete!
Configure Shellinabox
Shellinabox has a built-in web server that runs as a web based SSH-Client and listens on port 4200. For security reasons, you may change this default port to a random port (For eg: 4312 or whichever is free). By default a new self-signed SSL certificate gets created automatically under “/var/lib/shellinabox” to use HTTPS protocol.
How to find which port is free
#telnet localhost <port_no>
or
#netstat -anp | grep <port_no>
On Debian & Ubuntu
#vim /etc/default/shellinabox
# TCP port that shellinboxd's webserver listens on SHELLINABOX_PORT=4200
On RHEL, CentOS & Fedora
# vi /etc/sysconfig/shellinaboxd
# TCP port that shellinboxd's webserver listens on PORT=4200
Start Shellinabox service daemon
Once the configuration is completed, you can start the service by issuing following command:
On Debian & Ubuntu
#service shellinabox start
On RHEL & CentOS
#service shellinaboxd start
Verify the Service
Check if the service has started properly and listens on port 4200 (port might be different based on the above configuration) using netstat command as shown below:
root@ubuntu:# netstat -anp | grep shellinabox tcp 0 0 0.0.0.0:4200 0.0.0.0:* LISTEN 31331/shellinaboxd
How to use Shellinabox on the browser
Open up your web browser and navigate to https://server-ip:4200. Now you should be able to see a web-based SSH terminal as shown below prompting for login. You can login using your SSH username and password and upon successful, you would be presented a shell prompt.
Upon logout: