Saturday, May 06, 2006

Adding root to Ubuntu

Every Unix system, and most Linux systems, come with a root account. This is the ultimate superuser, one who can control everything about the machine, including the issuance of the famous command:

# rm -fr /

Warning: Don't try this at home. Oh, what the heck, if they tried it already they won't be reading this now.

Anyway, Ubuntu doesn't come with the root account enabled. The justification is three-fold: first, having a root account that can be accessed via login makes it easier for a malicious user, who only has to have the root password, to wreck havoc on the system; second, having root enabled allows all sorts of mischief to occur that can't happen inside a user account; and third, everything that needs to be done can be done using the sudo command. The necessity of the sudo pre-command, in this view, makes the user stop and think before do something that can cause damage. — Not that you can't do

$ sudo rm -fr /

but now you have to type sudo and enter your password before erasing everything on your system.

Nevertheless, it is sometimes useful to be in a shell with root access, say when you want to clean up a lot of junk at once. So Ubuntu provide a means of activating the root account. Well, not activate, actually, it's already there. What you need to do is provide the root account with a password.

There are many places where you can find how to do this, here's one of them. The simple procedure: starting from a terminal window in your account:

$ sudo su
Password: YOUR password goes here
# passwd
Enter new UNIX password: ROOT password goes here
Retype new UNIX password: Repeat ROOT password

Now whenever you want to work as root, open a terminal window and type:

$ su
Password: Enter root password

You are now free to totally mess up your machine.


Anonymous said...

You know, you can always just type "sudo -i" without the quotes and type "exit" when you want to exit root.

rcjhawk said...

Huh. Never knew that, thanks.