How to Use the sudo Command Correctly
Good practices and the risks to avoid, like running unreviewed scripts with elevated permissions.
sudo ("superuser do") runs a one-off command with elevated permissions, without needing to fully log in as root.
sudo apt update
It will ask for your own password (not root's) to confirm.
Good practices
- Only use it when the command genuinely needs it — don't put it in front of normal commands "just in case" when they work fine without it.
- Read carefully what a command does before running it with sudo — with elevated permissions, a mistake has more room to cause real damage.
- Never run a script with sudo if it's downloaded from a source you don't know well.
sudo remembers your authentication for a few minutes after first use — that's why it doesn't ask for your password on immediately consecutive sudo commands, but it will ask again after that period of inactivity.
Warning: avoid piping downloaded content directly
into sudo (curl something | sudo bash) without checking
first what that script does — it's a common way unverified code ends
up being recommended to run with full permissions.
Frequently asked questions
Why doesn't sudo ask for my password every time?
It remembers your authentication for a few minutes after first use, so it doesn't ask on every consecutive command — after that period of inactivity, it will ask again.
Is it dangerous to run 'curl | sudo bash'?
It can be if you don't check what the script does beforehand — you're running downloaded code directly with full permissions, with no chance to review it first.