AI Hints
Home›Linux Tutorial›Managing Users
Linux · Lesson 70 of 120

Why Not Always Root?

Least privilege.

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

If root can do anything, why not just log in as root, and never be bothered by permission denied again? It's tempting. But it's one of the worst habits you can have.

Why Not Always Root?
From the video: Why Not Always Root?
  • Why not just be root?
  • No more permission denied
  • A very bad habit

Why root is risky

As root, a single typo can wipe the system, and nothing will stop you. Any program you run also gets root's power, including a bad one you downloaded by mistake. And on a shared server, you lose the record of who did what. Permission denied is often Linux saving you from yourself.

Typosnothing stops them
Bad programsget full power
No recordof who did what
Permission deniedoften a good thing

Two ways to work

The safe way has a name, least privilege. Work as a normal user, with just enough power for everyday jobs. And use sudo for the few moments you really need more. On many servers, logging in directly as root is switched off completely.

Always root

  • Every command is dangerous
  • Mistakes are fatal
  • No audit trail

Normal user + sudo

  • Safe by default
  • Power only when asked
  • Every sudo is logged

If you really need a root shell

Sometimes you have many admin commands to run in a row. Sudo dash I opens a root shell. The prompt changes to a hash sign, to warn you. Do the work, then type exit straight away, to go back to being yourself.

keyvalue
sudo -iopen a root shell
# promptyou are root now
exitback to your user
Keep it shortleave as soon as you can

Summary

Work as a normal user, and use sudo only when needed. That's least privilege. If you open a root shell, leave it quickly. Next, adding new users.

Key takeaways
  • Least privilege
  • sudo when needed
  • sudo -i, then exit
Next up: Adding Users — useradd and passwd