kdmurray.blog

The crossroads of life and tech

Ubuntu School – GUI (xubuntu-desktop) for Ubuntu Server

Whether it’s because you’re not fully versed in the power of the command line, or you just want to use a tool that will speed things along like gparted, the command-line isn’t always the best tool for the job. Sometimes you just need a GUI, even if it’s just for a few minutes. I’m going to walk through how to do the installation on Ubuntu 11.10 with the assumption that you only want the GUI occasionally, and don’t want it consuming server resources all the time.

The first step is to get the GUI tools installed. sudo apt-get update
sudo apt-get upgrade
sudo apt-get install xubuntu-desktop

That was the simple part. At this point you now have the GUI installed, but it will start the GUI every time the system boots, loading all of that extra cruft into memory. The next steps that I followed from a post on Techinote shows the steps to disable the automatic startup of the GUI environment.

sudo apt-get install lightdm
sudo nano /etc/default/grub

find the line GRUB_CMDLINE_LINUX_DEFAULT and set it to GRUB_CMDLINE_LINUX_DEFAULT="text"

sudo update-grub
sudo update-rc.d -f lightdm remove
sudo shutdown -r now

Done!

Your system will now be at the text-based login screen (as it was before this all started). When you need to use the graphical environment, simply type startx and it will move you into an already authenticated GUI desktop environment. This will allow you to setup and configure tools with a GUI (like CrashPlan) without having to rely the UI being constantly loaded and running in the background.

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 – sudo Your Last Command

Sometimes we just forget that we need to specify elevated privileges on our Ubuntu machines. I do it all the time, particularly when I’m setting up a new machine.

Thankfully there’s a shortcut for those of us who are forgetful. If I want to restart the box I can use a command like:

shutdown -r now

But of course that command requires elevated privileges:

shutdown: Need to be root

With the fantastic !! argument for sudo you can repeat your last terminal command:

sudo !!

Now you can quickly and efficiently re-run that last command you forgot to sudo!!

Ubuntu School – DHCP Release and Renew

It’s not uncommon to need to release/renew the IP address for a given machine. This is particularly true if you’re doing any kind of maintenance on your network, or are troubleshooting pretty much any kind of Internet problem. I never seem to remember how to do this, so I’m including this post as much for my own benefit as anything.

What I’m talking about is the Ubuntu equivalent of these windows commands ipconfig /release ipconfig /renew

From an Ubuntu terminal type: sudo dhclient -r sudo dhclient

Much like the Windows equivalents you can also specify these actions for a specific interface if your situation requires.

sudo dhclient eth0

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!

Creating ISO Images from the OSX Command Line

A super fast way to create ISO images (or any kind of bit for bit copies) from the OS X (or linux, or unix) command line is to use the DD command. This isn’t without it’s risks since the DD command will duplicate byte for byte all data from one location to another, but once you’ve found the necessary information you can easily replicate data.

I needed to create a copy of my Windows XP installation CD to use for setting up new virtual machines. Since it’s quicker to install VMs from an ISO image rather than from the installation media I wanted an ISO of my CD. The built in OS X disk utility can make this work… in theory. My copy of disk utility (on Snow Leopard) didn’t want to recognize the CD. So I turned to my command line knowledge.

I should also note that before you can read the CD using DD, you will need to unmount it:

sudo umount /dev/disk1s0

You’ll be prompted for your administrator password, then you’re in business.

To create an image of a CD (or DVD or anything else…) use the following:

dd if=/dev/disk1s0 of=/Users/kdmurray/Desktop/WindowsXP.iso bs=64k

  • if= input file, in this case our Windows XP CD
  • of= output file, the actual ISO file you want created
  • bs= block size, the size of chunks the tool will work with

I did a few speed tests at 16k, 32k, 64k, 128k, 256k and 1M and found that the 64k seemed to be the ideal block size on my machine. This will vary by CPU, and possibly by hard drive controller, so do a few contolled tests first. To do a test, start the copy process, then stop it after 20-30s (ctrl-c). Whichever one copied the most in 30s is the one you should use.

That’s all she wrote, folks. Happy command-lining. :)