Thursday, 13 March 2008

Activating root account in OS X to enable sudo

This is the 2nd time I've had to do this and again have ended up
trawling the net for information, so I'll put it here.

If installing ruby gems, you need to do it as root or to do 'sudo gem
install [gem name]'

But you can't sudo if there's no root account!

So....

1. Enable root

In OS X 10.5 - you do it using the Directory Utility application. Log
in on an Admin account, run Directory Utility, and in the Edit menu,
select 'Activate Root account' (or a menu item similarly named). You
then enter the root password and verify.


2. Add your normal account to sudoers file.

Run visudo - a command-line util to edit the sudoers file in
/etc/sudoers, which contains the users or group that are allowed to
su-su-sudio.. er, ahem.. run sudo. :P

Using visudo is better than editing sudoers file directly because it
prevents any changes being saved if there are any incorrect entries.
Incorrect entries are BAD news for sudoers, since it prevents you from
doing sudo, and you have to call sudo to edit it or run visudo!
(chicken or egg!)

Under the section "# User privilege specification" - add a similar
entry with your username, like:

[username] ALL=(ALL) ALL

In this case, the username is the unix user, not the long Mac user
name you see when you log in.


3. Log out of the Admin account, then try doing something with sudo, like

sudo gem install mechanize

to see the results of your handiwork.

Gurus, please send corrections if any of the above is not exactly correct!

No comments: