Becoming the Superuser
Every Macintosh has a special user named root—the superuser or administrator on a Macintosh—who has the privileges to do anything at all on the system. Ordinary users are restricted: they can run most programs, but in general they can modify only the files they own. An administrator, on the other hand, can create, modify, or delete any file and run any program on a given Mac.
If you administer your Mac, you might never need to use the root account.[23] Rather, any account can be set up with administrator privileges (also called root privileges) and have all the same power as root. To do this, run System Preferences, visit Users & Groups (Lion) or Accounts (earlier versions of OS X), select the desired user, and check the checkbox “Allow user to administer this computer.” (Only an administrator can elevate other users to be administrators.)
Any user who is an administrator can easily become the superuser and
run arbitrary commands. You needn’t log out and log back in to do this;
just preface any shell command with sudo and provide your password:
➜sudoPassword:command here*******
For example:
➜ls /private/secretsView a protected directory ls: secrets: Permission denied It failed ➜sudo ls /private/secretsTry with sudo Password:*******secretfile1 secretfile2 It worked!
After the command has run, you’ll be your ordinary self again, with
one extra bonus. Future sudo commands
will not prompt for your password, making it easier to run multiple
sudo commands in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access