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.
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:
Edit the line that reads “ssl=1,” change it to “ssl=0”
Now you can access Webmin via: http://www.yourserver.com:10000/
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:
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.
-> 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
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).