What are sudo and chmod? (and when it is safe to run them)
In one sentence:sudo runs a single command with administrator power, and chmod changes who may read, write, or run a file; both are common fixes for permission errors, and both deserve a look before you press Enter.
What it actually is
sudo and chmod are the two commands people paste most often without reading them, usually seconds after a permission denied error. They solve different problems and carry very different risks. sudo, short for “su do” and commonly read as “superuser do,” runs one command as your machine’s administrator account (called root on Mac and Linux). Your everyday account is deliberately fenced off from system folders and other users’ files. Put sudo in front of a command, type your own password, and for that one command the fences come down. It’s like borrowing the master key to the whole building for thirty seconds: whatever the command does, it now does with full authority, anywhere. By default that approval lasts about five minutes per terminal before sudo asks again.
chmod, short for “change mode,” edits the rules attached to a single file or folder: who may read it, who may write it, and who may execute it (run it as a program). Those rules exist in three copies, one for the file’s owner, one for its group, one for everyone else. Running chmod +x deploy.sh flips just the “this file may be run” switch, normally in all three copies at once, and needs no password at all when you own the file. Where sudo borrows the master key, chmod re-labels a door you already own.
The cryptic numbers, like chmod 755, are those same switches written as digits. Each digit is a sum (read 4, write 2, execute 1), and the digits cover owner, group, and everyone else in that order.
| Command | Owner may | Everyone else may | Reasonable for |
|---|---|---|---|
chmod 644 notes.txt | read, write | read | ordinary files |
chmod 755 deploy.sh | read, write, run | read, run | scripts and folders |
chmod 777 anything | everything | everything, including write | almost nothing |
Why your AI just did this
Your agent suggests chmod +x all the time because it’s the standard follow-up to writing a script. When Claude Code creates backup.sh and then runs ./backup.sh, the shell answers permission denied: new files aren’t executable until someone says so. chmod +x backup.sh is the correct, boring fix, and agents often apply it on their own.
sudo appears for bigger asks: installing a tool for every account on the machine, writing into system folders like /usr/local, starting a server on a privileged port. Your agent often can’t finish these itself, because sudo wants a password typed at a live prompt and an agent session usually has no way to type one. So it hands you the command to run. That handoff is your moment of control. Forum culture treats sudo as the universal unjammer, and models trained on those forums inherited some of the reflex, so a suggested sudo deserves the same scrutiny as a fix from a random Reddit thread. It’s also the opposite move from sandboxing: a sandbox shrinks what a command can touch, while sudo grows it to the whole machine.
When you’ll run into it
-bash: ./script.sh: Permission deniedright after your agent writes a script. Onechmod +xfixes it.sudo: a terminal is required to read the passwordin your agent’s output when it tried sudo with nowhere to type a password.npm ERR! code EACCESonnpm install -g, the error whose forum replies are wall-to-wall “just sudo it.” npm’s own docs say to use a version manager instead.- A sudden
Password:prompt after you paste a command starting withsudo. That’s sudo asking you to confirm with your own password. - A tutorial or old Stack Overflow answer promising that
chmod 777makes a web server or upload-folder error go away. It will, the way removing your front door makes losing your keys go away.
What to check
- Paste any command containing
sudoback to your AI and ask what it does, what it touches, and why it needs administrator power. Run it once the answer makes sense to you. - Try the command without
sudofirst. If it fails on a single file you own, a targetedchmodon that file is the smaller fix. - Run
ls -l <file>before and after achmod, so you can see what changed; therwxletters at the left are the switches chmod flips. - Reach for
chmod 755on scripts and644on data files instead of777. If a fix truly requires 777, something else is misconfigured, usually the file’s owner. - Treat
curl ... | sudo bashinstall one-liners as the highest-stakes paste there is: they run a stranger’s script with full power in one step. Read the script first, or have your AI read it. - Skip the fix if you can’t say in one sentence what it grants. That single rule filters out most of the damage, and it’s the heart of least privilege.
Say it like a dev
Instead of: “the terminal is asking for my password, is that bad” Say: “this command starts with sudo, so it runs as administrator. Explain what it changes before I run it.”
Instead of: “chmod 777 fixed it” Say: “777 gave every account on the machine write access. What’s the tightest mode that still works here, 755 or 644?”
Instead of: “the script my AI wrote won’t run” Say: “the script is missing its execute bit. Run chmod +x on it.”
People actually ask
“What does sudo actually do when I put it in front of a command?”
It runs that one command as root, the administrator account, instead of as you. That removes nearly every restriction the system normally places on the command: it can write to system folders, overwrite protected files, and change anything on the machine. Your password confirms it's you asking, and by default the system remembers it for about five minutes in that terminal.
“Why is chmod 777 bad if it makes the error go away?”
chmod 777 gives every account and every program on the machine permission to read, write, and run that file. The error goes away because you removed all the protection, including the part protecting you. On anything connected to the internet, a folder everyone can write to is a standing invitation for malicious code. 755 for scripts or 644 for data files solves most problems with a much smaller grant.
“My AI told me to run a command with sudo. Should I just do it?”
Ask it to explain the command first: what it installs, what it touches, and why administrator power is needed. Agents pick up the internet's 'just sudo it' habit, and a wrong sudo command can damage things your normal account can't even reach. A good rule: never run a sudo command you can't explain in one sentence. Once the explanation makes sense to you, running it is fine.
Related terms
Checked against
Just met this in a real session? Glim reads it in plain words.
Paste what your agent just did, a git diff, your terminal, or its summary, and Glim tells you what changed and what to check before you ship. Nothing stored.
Explain my session →