2009-05-09

Bonus Post: Using sudo in Debian

If you're familiar with Ubuntu or other Linux distros, you may be familiar with the sudo command. If you're not familiar with sudo, this is a command that lets you run a command as another user. Typically, on home computers, this is used to allow you to run commands as the root user, rather than having to log in as the root user. You may notice that, by default, your user is not in the sudoers file. Personally, I like sudo, so I'm going to add my user to the sudoers file.

In order to edit the sudoers file, we have to be logged in as root. Let's pull up a terminal session and run the following command:

$ su

This will prompt you for the root password and then you should notice you're at a # prompt rather than a $ prompt. If you try to edit the /etc/sudoers file right now, you'll notice that it does not allow any user write access. This is to prevent user error when editing this file by formatting things incorrectly or something. The way you should edit this file is with the visudo command. It is possible to edit this with some other commands, but it is not recommended. To open up the file for editing, we should run the following command:

# visudo

You should see a line in the file that looks like:

root ALL=(ALL) ALL

To get the same behaviour you may be used to seeing in Ubuntu or other Linux distros, you'll just want to add a line almost identical to the above line, only substituting your user name for "root":

grabag-linux ALL=(ALL) ALL

To save the changes, hit Ctrl + x, this will prompt you with a question asking to save the changes. Answer "y" to save the changes, and this will prompt you for the location of the file to save. By default, it should populate the file name /etc/sudoers.tmp, just delete the .tmp off the end of the file name to save it to the correct location. This will prompt you saying that the file already exists and asks if you want to overwrite the file; answer "y" to save and quit visudo. Now you can exit your root session and test out your new sudo authority:

# exit
$ sudo apt-get update

That does it for this bonus post. I'll be back tomorrow with the regularly scheduled post on configuring the wireless adapter on the Mini 9.

No comments:

Post a Comment