Webmin Installation (manual and automated)

This will be the first of our guides where I’ll show you how to do it from a command line and I’ll then show you how to put it all together and automate the install. The reason I ended up doing this was that I wanted to automate my Raspberry Pi setup as much as possible since I was doing it very frequently when I first gotthe device and kept wanting a fresh Raspbain installation to work on. So I ended up automating my whole install process which resulted in a script which runs and does everything from adding users, setting up wifi, starting file shares, installing software, …What is Webmin?
If you are reading this site you probably know what  Webmin is since you likely got here through a Google search. If you didn’t come via that route then Webmin is a brilliant GUI web interface for managing linux based devices. You can do user management, disk management, config file management (think crontab, startup scripts, …), add/remove startup or shutdown jobs, update software, …
You’ll find more here: http://www.webmin.com/

Basically most command line stuff I have done via SSH in the past can be done in Webmin in a nice web interface.

Install dependencies

apt-get -y install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python

Download & install Webmin, then clean up download. You could find the latest Webmin installation file location at: http://sourceforge.net/projects/webadmin/files/webmin/ or you could use the latest version which they always keep up to date at this link: http://www.webmin.com/download/webmin-current.tar.gz

cd /usr/bin
wget http://www.webmin.com/download/webmin-current.tar.gz
gunzip webmin-*.***.tar.gz
tar xf webmin-*.***
cd webmin-*.***
sudo sh setup.sh

Webmin runs with SSL by default if I recall correctly. I’m pretty sure you can deselect this option during installation but if you decide just to go with it then you’ll end up with errors thrown by Chrome and IE when accessing the site since you’ll not be using a proper externally validated SSL certificate. You could of course go and get yourself a free one (http://arstechnica.com/security/2009/12/how-to-get-set-with-a-secure-sertificate-for-free/) – a post for another day. Or you could add an exception to  Chrome and IE since you trust the server you are accessing anyway so there really is no danger to you (http://www.ehow.com/how_8566511_disable-ssl-webmin-miniserv.html) but to be honest, for some reason I could never properly add the exception no matter how much Googleing I did.

To disable SSL from Webmin if you didn’t do it during setup you can:

nano /etc/webmin/miniserv.conf

Edit the line that reads “ssl=1,” change it to “ssl=0”

/etc/init.d/webmin restart

Now you can access Webmin via: http://www.yourserver.com:10000/

Automation!

The principles you learn in this guide you can use as the basis for a whole host of automation on your NAS. From automating other installation tasks, to making backups or regular jobs run without requiring manual input.

To automate the installation we’ll be using a tool called Expect (http://expect.sourceforge.net/) which is superb for scripting and automated tasks. It looks out for command line output and responds to it in a pre-defined manner. For example in the Expect script we are about to use we kick off the Webmin install task (as above) and the Expect tool watches for Webmin to ask us, “Config file directory”. Once Expect sees this it will send the keystroke for ‘Enter’ to use the default installation path. We could also get Expect to send keystrokes to change the installation path should we choose.

Anyway, I have written a little bash script and an Expect script which automate the Webmin installation. The scripts are hosted here on a Github repo which I’m using just for hosting blog files which Blogger doesn’t have the functionality to host:
https://github.com/danteali/blog_files/blob/master/webmin.sh

Open the links and look at the files closely. They are very simple and it should be very clear what is going on. We are going to download them from Github to our server and make one small change (adding the Webmin password) then run them. You should only do this with things you trust. If this was a complex script and you didn’t know what it did you probably shouldn’t use it as it could be doing anything to your machine and would potentially be a security risk.

You’ll also find that the bash script (webmin.sh) comes in a nice teamplate which is really useful and can be used to build your other scripts in. It has error reporting and you can output in various colours easily.

So, briefly, here is what the scripts do. We run webmin.sh …

  • The script installs some dependencies for Webmin and also installs Expect.
  • Downloads the latest Webmin installation files
  • Starts the WebminSetup.exp Expect script
  • The WebminSetup.exp Expect script starts the Webmin installation file (setup.sh – same as manual steps above)
  • It watches the output from the Webmin installer until particular keywords appear. These indicate the installation steps where user interaction is needed. Expect then issues keypresses etc to mimic user interaction.

Anyway, lets get to it…
1. Create a temp directory and download our scripts

mkdir ~/webmin_temp
cd ~/webmin_temp
wget https://github.com/danteali/blog_files/blob/master/webmin.sh https://github.com/danteali/blog_files/blob/master/WebminSetup.exp



2. Add your Webmin password to the Expect script.

nano ~/webmin_temp/WebminSetup.exp

-> Replace “YOURPASSWORD” with the password you want to use to log into Webmin. Remember to do it in both places.

3. Run the webmin.sh script

sh ~/webmin.sh

4. Delete the temp deirectory

rm -rf ~/webmin_temp

Now you can access Webmin via: http://www.yourserver.com:10000/ (using ‘admin’ and the password you picked earlier).

Useful sources:
http://www.webmin.com/deb.html

Leave a Reply

(email optional)


Warning: Undefined array key "rerror" in /home/public/blog/wp-content/plugins/wp-recaptcha/recaptcha.php on line 291