Superuser Privileges with sudo

Your Mac OS X user account runs with restricted privileges; there are parts of the filesystem you don’t have access to, and there are certain activities that are prohibited until you supply a password. For example, when you run the Software Update utility from System Preferences, Mac OS X may ask you for your password before it proceeds. This extra authentication step allows Software Update to run installers with superuser privileges.

You can invoke these same privileges at the command line by prefixing a command with sudo, a utility that prompts you for your password and executes the command as the superuser. You must be an Admin user to use sudo. The user you created when you first set up your Mac will be an Admin user. You can add new Admin users, or grant Admin status to a user in System Preferences Accounts.

Tip

What if you don’t know your administrative password? If you forgot your password, read the Mac OS Help to direct you. You might need to reboot your computer off your original Mac OS X install CD-ROM, then when you get to the installer, select the Reset Password... option from the Installer menu. The program will then prompt you for a new password and set it for your machine. Reboot again (without the CD-ROM), and you should be set forever.

You may need to use sudo when you install Unix utilities or if you want to modify a file you don’t own. Suppose that you accidentally created a file in the /Users directory while you were doing ...

Get Learning Unix for Mac OS X, Second Edition 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.