Access via Web SSH inside a Docker Container

Sometimes, a SSH access on a host may be blocked outside the corporate domain for security reasons. One solution to access it anyway is through a web browser. The Shell in a Box tool (https://github.com/shellinabox/shellinabox) makes this possible.

sudo docker container run --rm \
--name shellinabox \
-p 4200:4200 \
-e SIAB_USER=myusername \
-e SIAB_PASSWORD=mypassword \
-e SIAB_SUDO=true \
-v $PWD/dev:/usr/src/dev \
sspreitzer/shellinabox:latest
Preparing container ..
Starting container ..
Executing: /usr/bin/shellinaboxd --debug --no-beep --disable-peer-check -u shellinabox -g shellinabox -c /var/lib/shellinabox -p 4200 --user-css Normal:+/etc/shellinabox/options-enabled/00+Black-on-White.css,Reverse:-/etc/shellinabox/options-enabled/00_White-On-Black.css;Colors:+/etc/shellinabox/options-enabled/01+Color-Terminal.css,Monochrome:-/etc/shellinabox/options-enabled/01_Monochrome.css -s /:LOGIN
[server] Version 2.20
[server] Command line: /usr/bin/shellinaboxd --debug --no-beep --disable-peer-check -u shellinabox -g shellinabox -c /var/lib/shellinabox -p 4200 --user-css Normal:+/etc/shellinabox/options-enabled/00+Black-on-White.css,Reverse:-/etc/shellinabox/options-enabled/00_White-On-Black.css;Colors:+/etc/shellinabox/options-enabled/01+Color-Terminal.css,Monochrome:-/etc/shellinabox/options-enabled/01_Monochrome.css -s /:LOGIN
[server] Listening on port 4200...
[ssl] Support for PFS enabled...
[ssl] Server context successfully initialized...
[ssl] Auto-generating missing certificate "/var/lib/shellinabox/certificate.pem" for "2fe07c9d95ab"...
[ssl] Certificate successfully generated.
  • SIAB_PASSWORD: Specifies the password,
  • SIAB_SUDO: indicates whether the activated user is getting sudo,
  • -v $PWD/dev:/usr/src/dev: specifies the sharing directory between the host and the Docker container.
sendCommand(SecurityInterstitialCommandId.CMD_PROCEED)
bb965957c742 login: myusername                                                                 
Password:
Welcome to Ubuntu 18.04 LTS (GNU/Linux 3.10.0-1127.18.2.el7.x86_64 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
myusername@bb965957c742:~$

Interests in the full lifecycle: design, Agile Coaching, development, testing, DevOps, Cloud, Management 3.0, ITIL. It defines me.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store