sudo

From Mac Guides

Jump to: navigation, search

sudo is a Terminal command used to execute a command as another user, by default, the root user. This is useful if, for example, a system file or another user's file needs to be edited. sudo will ask for a password, and if successful, will not ask for a password for another 5 minutes.

Examples

To edit a default system plist:

 sudo open /Library/Preferences/com.apple.sharing.firewall.plist

To delete a file owned by another, without changing permissions of the parent directory:

 sudo -u george rm ~george/Documents/somefile.txt

Man Page Excerpt

sudo allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file. The real and effective uid and gid are set to match those of the target user as specified in the passwd file and the group vector is initialized based on the group file (unless the -P option was specified). If the invoking user is root or if the target user is the same as the invoking user, no pass- word is required. Otherwise, sudo requires that users authenticate themselves with a password by default (NOTE: in the default configura- tion this is the user's password, not the root password). Once a user has been authenticated, a timestamp is updated and the user may then use sudo without a password for a short period of time (5 minutes unless overridden in sudoers).