AI Hints
Home›Linux Tutorial›Running and Owning
Linux · Lesson 69 of 120

sudo and root

Admin powers.

⏱ 2 min read▶ Video at 1:30:27🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Every Linux system has one special user called root. Root can do anything. Read any file, delete any file, change any setting. That's very powerful, and very dangerous. So normally, you borrow root's power for just one command, with sudo.

sudo and root
From the video: sudo and root
  • root can do anything
  • Powerful, and dangerous
  • Borrow it with sudo

Normal user, then sudo

As Sam, we can't read the protected file slash ETC slash shadow. Permission denied. But with sudo in front, the command runs as root, and it works. Sudo head shows the first lines. Who am I, with sudo, even says root.

Terminal
head -n 2 /etc/shadow
head: cannot open '/etc/shadow' for reading: Permission denied
sudo head -n 2 /etc/shadow
root:*:20750:0:99999:7:::
daemon:*:20750:0:99999:7:::
sudo whoami
root

How sudo works

Sudo means, super user do. When you use it, Linux usually asks for your own password, not root's, to prove it's really you. Only users in the sudo group are allowed. And every sudo command is written to a log, so there's a record of who did what.

sudo cmdrun one command as root
Passwordyours, not root's
Allowedmembers of the sudo group
Loggedevery use is recorded

Use it carefully

Sudo turns off all the safety nets. A typo with sudo RM can destroy the whole system. So use sudo only when you really need it, like installing software, or editing system settings. If a command works without sudo, don't add it.

keyvalue
Use sudo forinstalling, system settings
Not foryour own files
Dangersudo rm -rf with a typo
Ruleonly when needed

Summary

Root can do anything. Sudo runs a single command as root, after checking your password. Use it only when you need to. Next, why you shouldn't just log in as root all the time.

Key takeaways
  • root = super user
  • sudo cmd
  • Only when needed
Next up: Why Not Always Root? — least privilege