SPY
HILL
Research
|
Spy-Hill.net
|
| Poughkeepsie, New York | [DIR] [UP] |
The superuser (i.e. "root") account, which controls everything in Unix, is turned off by default in most Mac OS X installations. These instructions tell you how to enable the Unix "root" account on Mac OS X.
Last updated: 9 April 2010
|
The default Mac OS X installation has the Unix "root" account disabled. This is generally a good thing, because the casual user does not need all the powers granted to this "superuser" account. But it can be useful to be able to become "root" to fix something. You can follow the instructions below to enable the "root" account, which will make it easier for the "root" user to get a command shell prompt.
You can also use these instructions to remove a root password that you have forgotten, or to reset any user password.
Making changes like this to the system requires administrative privileges. You will need to know the password for the "Admin" account on your machine. If you do not have that then the only way to get administrative access to the machine is to reboot from an Installation CD and find the menu item for "Password Reset".
Whenever you use the "root" or "Admin" accounts it is a good idea to follow the Principle of Least Privilege. You should only take on the extra privileges to do a particular job, and then release those privileges when you are done. (Your normal, every day user account should not have administrative privileges!)
If you just want to perform occasional system administration tasks then you don't really need to enable the "root" account. You can log in as the "Admin" user, open the Terminal application, and give any single command prefixed by the sudo command. Examples of this are shown below.
Since this page first started I have become aware of three different ways to enable the root account. The original way I published is the "detailed" method using NetInfo Manager. It is the same way you would reset any user's password on a NeXT computer (and now Mac OS X as well). There is also a much quicker way to enable the root account using a menu item in NetInfo Manager. (However, NetInfo is not included in MacOS&Nbsp;X 10.6 (Snow Leopard)) Or you can open a command shell in the Terminal application and use the sudo command. Pick the one that works best for you:
After you have enabled the root account, there are
three different ways that you can become "root"
to perform system administration tasks.
The sudo command is a good way to do this, because it runs
only one command as the "superuser" at a time. For example
If you need to do something which requires more than a single command
then you can open a command shell running as "root".
You can still use the sudo command to do this.
When logged in as the "Admin" user open the Terminal application and
give the command
On MacOS X the "Admin" account is configured so that it is
allowed to use the "sudo" command, so you can get by without enabling
the "root" account.
The more traditional way to become "root" in Unix is the su
command.
This will work for the "Admin" user but will fail for a non-privileged
user account because of another old Unix custom which is respected by
Mac OS X: only members of the "wheel" group are allowed to su to
root.
There are two ways around this.
First of all, you can use NetInfo Manager (as described below) to add
your user account to the "wheel" group.
Follow the instructions below to run NetInfo Manager, but select the
"groups" map instead of the "users" map.
Find the "wheel" group, edit the "users" property, and add the name of
your user account to the list.
But there is an easier way.
Local users who are not in the "wheel" group cannot su to "root", but
can still ssh to the "root" account.
Give the command
Remember, as "root" you should do what needs to be done and then go
back to being an unprivileged user.
If you don't have this in the dock for the Admin account you
should probably drag it there.
It is very useful for system administration.
At the command prompt type this command:
At the command prompt type this command:
You cannot simply enter a new password here, because Unix stores
an encrypted version of the password in the user database
(passwd map).
You will need to use the passwd command (step 7 below) to
enter a new password.
Be sure to pick a good password for the "root" account.
If your computer is connected to the Internet is may be possible for
someone to get in to your computer as "root" if you have a weak
password.
Some useful guidelines for picking a good (or bad) password may be
found here.
On Becoming root
Whenever you use the "root" or "Admin" accounts it is a good idea to
follow the Principle of Least Privilege.
You should only take on the extra privileges to do a particular job,
and then release those privileges (i.e. go back to using your normal
user account).
% sudo cat /etc/sudoers
will show the contents of the sudoers file, which controls
who is allowed to use the sudo command. You will have to
give your password for any "sudo" command to work, and your
account must be listed in the sudoers file.
% sudo tcsh
This will spawn a new tcsh command shell running as "root". You can
give as many commands as you need, and then type `exit` when you are done.
% ssh root@localhost
and enter the "root" account password and you will have a root shell.
Type `exit` when you are done.
Quick Menu Method, using NetInfo Manager
This is the easiest method to enable the "root" account on a Mac if
you are more of a GUI person, but it won't :
Quick Method using the Command Line Interface (CLI)
This is the easiest method to enable the "root" account on a Mac
if you are more of a CLI person:
Macintosh HD -> Applications -> Utilities
-> Terminal.
% sudo passwd root
Enter Password:
Changing password for root
New password:
Verify password:
The first password you are asked for is the already existing password
for the Admin account, to prove that you are authorized to
make changes to this system.
After that, you enter the new root password (twice, for verification).
That is all, the "root" account is now enabled, with that password.
Detailed Method using NetInfo Manager
These instructions allow you to enable the "root" account, or to reset
the password for any user, not just "root".
To disable the "root" account, or any user account, follow the
directions above to edit the "user" map with NetInfo Manager, and put
a "*" in the passwd field.
Macintosh HD -> Applications -> Utilities -> Terminal
% nidump passwd .
(Don't type the "%" - that represents the Unix command prompt.
And don't forget the "dot" at the end, which indicates that the "password"
map to be dumped to the screen is the one on this machine, not the
password map from a remote server.)
You should see a line like this:
root:*:0:0:System Administrator:/var/root:/bin/tcsh
The "*" is where the encrypted password for the user would normally
go.
If the "root" account has a "*" then it is not possible for a user to
become "root".
Macintosh HD -> Applications -> Utilities -> NetInfo Manager
% su root
(Don't enter the %, that represents the Unix command prompt.)
When prompted for the password, just hit "return".
Then add a password with the `passwd root` command, like so:
# passwd root
Changing password for root
New password:
Verify password:
(Don't enter the #, that is the root command prompt on Unix.)
The password you type won't be printed on the screen, which is why
you are asked to type it twice for verification.
Acknowledgments
Many thanks to all those who have given me feedback on this page,
including Stephen Zinn and Damian Draper.
| Last modified: 09 April 2010 | Copyright © 2010 by Spy Hill Research | http://www.spy-hill.net /help/apple/EnableRoot.html |