Basics

What is sudo — and why it asks for your password, not the admin's

Illustration: a guard with a list stands by a door marked with a key, and the robot shows its pass

Here's an odd detail. You type sudo apt install git, and the terminal replies:

[sudo] password for artem:

Not "the administrator's password". Your own. Even though the command is about to run as the most powerful user on the system. How does that work — and why isn't it a security hole? Let's figure it out. Along the way you'll see why sudo is the most common way to break your own project.

What sudo is, in plain words

sudo is the command "run the next thing as another user". Most of the time that other user is root, the top user on Linux and macOS. Root can do anything: change system files, install programs for everyone, delete whatever it wants.

You normally work under your own name. You can touch your home folder and almost nothing outside it. That's on purpose: one careless command can't wreck the system.

Hence the name: substitute user do. Put sudo in front, and only that one command gets root powers:

sudo apt install git     # as root
git --version            # back to you

The powers don't "switch on for good". The next line is yours again.

Why it asks for your password

Here's the answer. sudo doesn't check whether you know root's password. It checks two things:

  1. You are you. Hence your password: maybe someone else is sitting at your laptop.
  2. You're allowed. The allow list lives in /etc/sudoers. On Ubuntu the sudo group is on it by default; on macOS, administrators are.

Think of a guard with a list at the door. The guard doesn't need the door's key — you need to be on the list and prove who you are. If you're not on it, the answer is blunt:

artem is not in the sudoers file.  This incident will be reported.

"Reported" isn't the police. The attempt just lands in the system log.

One more detail: after you type the password, sudo stops asking for a while. On Ubuntu that's 15 minutes. That's why a second command right after goes through silently. sudo -k ends that window.

The trap: sudo that breaks your project

Now the part that matters for a vibe-coder. A classic story: npm install -g says EACCES: permission denied. An AI or a forum suggests "add sudo". You do — and it works.

A week later it breaks even without sudo. Why? The command under sudo created files as root — say, a cache in your home folder. Now root owns those files, and plain you can't change them. Every new install fails with permission denied again, and you reach for sudo again. A snowball.

Same story with sudo pip install and with running your project as sudo npm run dev. Checking whether this is you is easy:

ls -la ~/.npm

How to read those owner and permission columns is in our list of terminal commands every beginner needs. If the owner column says root instead of your name, that's it. The fix is to take ownership back: sudo chown -R $(whoami) ~/.npm. Here sudo is appropriate — you're repairing a system mistake, not working around it.

The right way to install tools for yourself needs no sudo at all. For Node it's a version manager (nvm, fnm); for Python, a virtual environment (python -m venv .venv). Then your package manager puts everything in your own folder and root isn't needed.

When you really need sudo

A simple rule: sudo is for things that touch the whole machine, not your folder.

  • Installing system software: sudo apt install nginx.
  • Editing system settings in /etc.
  • Starting and restarting services: sudo systemctl restart nginx.
  • A server on a "low" port under 1024, like 80.

And never for npm install, pip install inside a project, git, or running your own app. If a command like that asks for sudo, it's a symptom, not a fix. First find out who owns the files.

Two handy extras. sudo !! repeats the last command, now with sudo — for when you forgot it. And sudo -l shows exactly what you're allowed to run.

FAQ

What's the difference between sudo and su?

su switches you into another user entirely and asks for their password. sudo runs one command and asks for yours. On Ubuntu root has no password by default, so only sudo works there.

Should I let an AI agent run sudo commands?

Better not. An agent runs commands as you — with sudo, as the whole system. If an agent wants sudo to install project dependencies, it's the same snowball as above.

Why does sudo say command not found when the command exists?

sudo has its own trimmed PATH and doesn't see programs from your home folder. We covered it in detail in why sudo says command not found.

Become an AI architect — don’t just read about AI

The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.

About the Academy
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →