kdmurray.blog

The crossroads of life and tech

Ubuntu School – Get Rolling with Webmin on Ubuntu Server 11.10

Even if some Linux purists would have you believe the command-line is the only way to go, the pragmatist in me will always take an appropriate GUI over a complicated command-line any day. You can run a lot of powerful services for your home network using one or more Ubuntu server machines. With the right tools you don’t need to be a Linux expert to make that happen.

The tool of choice is Webmin. This is a set of web-based tools which allow you to control virtually every piece of server-side software on you Ubuntu server. The GUI is intuitive and straight-forward, the documentation is excellent, and the project is under active development.

Because Webmin isn’t in the standard repositories you will have to do a couple of quick command-line changes to configure your system to be able to find and download the apt package.

sudo nano /etc/apt/sources.list

Once the file is open, add these lines to the bottom of the file

#########################

Package Sources for Webmin

deb http://download.webmin.com/download/repository sarge contrib deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

Those lines will add the necessary sources to apt for it to find the Webmin package. The Webmin package has also been digitally signed by its author. By default you will need to download the author’s key so that apt can use it to verify the Webmin package at install time. Fortunately, this is really easy to do.

wget http://webmin.com/jcameron-key.asc sudo apt-key add jcameron-key.asc

Now that all the prep work is done, it’s time to install Webmin.

sudo apt-get update sudo apt-get install webmin

All done! Now you can access administrative functions of your server’s services from the Webmin console: https://yourservername:10000/. This URL is also shown in the last few lines of the apt install details that are ouput to the command-line.

Running Shell Scripts from the Finder in OS X

Bad AppleOne of the things that drives me insane about the Mac on occasion is the ability of OS X to make some of the simplest “power-user” tasks very difficult. Case in point – the ability to execute a shell script from a finder window (or by extension, the desktop).

In most sane operating systems, including Linux and Windows, if you double-click on an executable file, it executes. It’s just that simple. If you create a batch file on Windows (anything ending in .bat or .cmd), the operating system treats that file type as executable and will try to run the contents as command-line commands. In Linux, an operating system which is similar under the hood to OS X, you need to set the “executable” bit in the permissions. This is certainly more of a super-user type task than simply renaming the file, but still quite simple — and consistent across the POSIX world… except for Apple.

chmod +x myscript.sh

So the question is, how do I do this on my Mac? The answer I’ve been given by several people until today was that you would need to use AppleScript or Automator (or Xcode) to create a program that could be run from the Mac GUI. As ludicrous as it seemed, Apple’s tendency to force users to do things the “Apple way” made that quite believable. However I found a post today on Adam Young’s blog from back in 2008 which showed that it is, in fact, possible to do this — it’s just a bit harder than on any other OS. Essentially you have to do both the Linux (chmod) step, and the Windows (specific file extension) step.

mv myscript.sh myscript.command chmod +x myscript.command

You need to use the .command extension for the Finder to actually attempt to run your shell script. An identical file with the execute bit set but with a .sh extension will simply open up in Xcode (or whatever editor you have set for .sh files).

Ubuntu School – Add an Existing User to a Group

Occasionally you need to grant an existing user some additional permissions to files, directories or applications. This typically means some kind of change in your permissions settings for the object in question. But because you can only have a single owner for a given object you need to be careful making these changes.

Something you can do, though, is extend the permissions on the object to a set of users by way of a group. Logically, a group is nothing more than a named collection of users who all have the same access (by way of that group) to some resource. Users in Ubuntu typically carry one primary, and one or more secondary groups (I won’t get into the differences here).

By adding group permissions to your resources (ie give the ‘payroll’ group read/write access to the ‘HR’ folder) you can simply add users to and remove users from the appropriate groups and be confident that their level of access to the resources on your machine is set correctly.

To add an existing user to an existing group:

sudo usermod -a -G payroll graymond

To remove a user from a group you use the same command. The catch is, you remove a user from a group by re-adding all of their groups and simply omitting the group you wish to remove them from.

sudo usermod -nG mkirkpatrick

The system will show you a list of the user’s groups.

marketing sales vanprinters torprinters

Then you simply run the usermod command as above, removing the group in question (in this case vanprinters)

usermod -G marketing,sales,torprinters mkirkpatrick

Ubuntu School – Creating a New User

There are two built-in commands for creating a user from the command-line in Ubuntu: useradd and adduser. useradd is the older command which has, for the most part, been deprecated in favour of the more user-friendly adduser command. Both will allow you to create new user accounts, set up home directories and generally move in the right direction, but adduser will prompt you for information you didn’t include whereas useradd will assume you didn’t want those things (ie create the home directory).

sudo adduser theboss

will produce an output similar to

Adding user theboss' ... Adding new grouptheboss' (1001) ... Adding new user theboss' (1001) with grouptheboss' ... Creating home directory /home/theboss' ... Copying files from/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for theboss Enter the new value, or press ENTER for the default Full Name []: Joe Bossman Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] y

And there you are! Happy user-creating!

Admin Links Plugin Updated to 1.4.0

It’s been a good long while since I’ve had the time to make any changes to the two WordPress plugins I’m supporting. In fact if WP 3.0 hadn’t broken one of my plugins there’s a good chance I wouldn’t have made this change either.

That said, there’s a fresh version of the Admin Links plugin available and this one is compatible with WP 3.0.

In case you’re not familiar with the plugin, it provides access to common admin features from the public side of the site. Visible to logged-in admins, and completely invisible to the great unwashed masses of the interwebs.

Download it directly from WordPress.org.

Moving? Redirect with htaccess and 301

Image Credit: Shannon K on Flickr

Image Credit: Shannon K on Flickr

If you’ve ever moved your site from one server to another, or changed domain names you know how difficult it can be to redirect all your old traffic to the new location. Here’s a quick trick to make the transition totally seamless.

Redirect 301 / http://kdmurray.net/

This will redirect every URL beneath the root (” / “) to it’s corresponding URL at mynewsite.net. So if you had a blog post from a couple of years ago that you migrated to the new domain, you can redirect the old URLs (which may have been cached in a search engine) to the new site to drive all that traffic to where it should be going.

In addition the 301 code (see HTTP 301) will tell web browsers & search engines that the page has been permanently moved which will help to ensure that the old site is no longer cached.

This should work with Apache on both Linux (OS X, unix etc.) and Windows.