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:
➜sudo
Password:command here
*******
For example:
➜ls /private/secrets
View a protected directory ls: secrets: Permission denied It failed ➜sudo ls /private/secrets
Try 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 ...
Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.