Root is the superuser account with complete access to everything on your Mac. It can read, modify, or delete any file - including system files that could break your computer.

You normally don't log in as root. Instead, you use sudo to run individual commands with root privileges.

Regular User vs Root

User Type Access
Regular user Your files, applications you install
Root Everything - all files, all settings, all users

Your normal account can't modify system files. This is a safety feature, not a limitation.

What is sudo?

sudo = "superuser do"

It runs one command with root privileges:

sudo nano /etc/hosts

You'll be prompted for your password. The command runs as root, then you're back to normal.

When You Need sudo

Common situations:

# Editing system files
sudo nano /etc/hosts

# Installing system-wide software
sudo cp myapp /usr/local/bin/

# Changing system settings
sudo systemsetup -setcomputersleep Never

# Managing services
sudo launchctl load /Library/LaunchDaemons/myservice.plist

When You DON'T Need sudo

Don't use sudo for:

  • Normal file operations in your home folder
  • Running applications
  • Using Homebrew (brew install doesn't need sudo)
  • Git commands
  • Most day-to-day work

If something asks for sudo unexpectedly, pause and think. You might be in the wrong directory or doing something wrong.

The sudo Password

When you run sudo, it asks for your password (not a separate root password). You must be an administrator on the Mac.

After entering it once, sudo remembers for about 5 minutes. Then it asks again.

Common sudo Commands

# Edit hosts file
sudo nano /etc/hosts

# Flush DNS cache
sudo dscacheutil -flushcache

# Change file ownership
sudo chown username:staff /path/to/file

# Change permissions on system files
sudo chmod 755 /usr/local/bin/myscript

# Kill a stubborn process
sudo kill -9 1234

The Root User Account

Mac has an actual root user account, but it's disabled by default. You can enable it in System Preferences → Users & Groups → Login Options → Network Account Server → Join → Open Directory Utility.

Don't enable it unless you have a specific reason. Using sudo is safer because:

  • Each command requires deliberate action
  • You can't accidentally stay logged in as root
  • There's an audit trail of what ran with elevated privileges

Safety Rules

  1. Never run sudo on commands you don't understand
  2. Be extra careful with rm -rf and sudo together - you can delete your entire system
  3. Don't use sudo to fix permission problems - figure out why permissions are wrong first
  4. Never run sudo commands from untrusted sources - attackers use sudo to gain control

"Permission denied" vs "Operation not permitted"

Error Meaning
Permission denied You might need sudo, or you're accessing another user's files
Operation not permitted Often a macOS security feature (SIP), sudo won't help

System Integrity Protection (SIP)

Even root can't modify certain system areas on modern Macs. Apple's System Integrity Protection prevents changes to:

  • /System
  • /usr (except /usr/local)
  • Built-in apps

This protects against malware - even if something gets root access, it can't modify core system files.

Checking If You're Admin

groups

If you see admin in the list, you can use sudo.

What Happens Without sudo

nano /etc/hosts

You can view the file, but when you try to save:

[ Error writing /etc/hosts: Permission denied ]

With sudo, it works because you're temporarily root.


Keep Learning

Understanding sudo and root keeps your Mac secure while giving you power when needed. The free course covers permissions and security concepts.

Check it out at Mac Terminal for Humans.