The principle of least privilege means every user, program and service gets only the access it needs to do its job, and nothing more. When an account is compromised or a program has a bug, the damage is limited to what that account was allowed to do, which is why running as a standard user, using scoped API keys and giving apps their own restricted database accounts are all applications of the same rule.
The definition of least privilege
The idea comes from Jerome Saltzer and Michael Schroeder's 1975 paper on protection in computer systems, which listed it as a design principle:
"Every program and every user of the system should operate using the least set of privileges necessary to complete the job."
NIST's current glossary gives the same idea in standards language: a system "should restrict the access privileges of users (or processes acting on behalf of users) to the minimum necessary to accomplish assigned tasks." Two details in both definitions matter in practice:
- It covers processes, not only people. A web server, a cron job, a CI pipeline and an API key are all subject to it.
- "Minimum necessary" is tied to the task. The question is never "is this person trusted?" but "does this task need this permission?". A trusted senior engineer reading email does not need domain admin rights while doing it.
Why least privilege matters: blast radius
Least privilege does not stop the first compromise. It limits what happens next. Compare one bug in two setups:
| Incident | Over-privileged setup | Least-privilege setup |
|---|---|---|
| SQL injection in a web app | App connects as the database superuser: attacker can read every database, drop tables, create logins | App account can only read and write its own tables: attacker gets those rows |
| Malware opened from an email attachment | User runs with full admin rights: malware can install drivers and disable security tools | User is a standard user: malware is confined to that user's files unless someone approves an elevation prompt |
| Leaked cloud access key | Key has administrator access to the whole account | Key can only write to one storage bucket |
| Compromised container | Process runs as root inside the container | Process runs as an unprivileged user |
In each row the bug is the same; only the permissions differ. That is the whole argument for the principle.
How NIST turns it into controls (AC-6)
NIST SP 800-53 Rev. 5, the control catalog used across US federal systems and widely borrowed elsewhere, puts least privilege in control AC-6. The base control says to allow "only authorized accesses for users (or processes acting on behalf of users) that are necessary to accomplish assigned organizational tasks." Its enhancements read like a checklist you can apply anywhere:
- AC-6(2): people with privileged accounts use a non-privileged account for everyday, non-security work.
- AC-6(5): restrict privileged accounts to specific named people or roles.
- AC-6(7): review assigned privileges periodically and remove what is no longer needed.
- AC-6(8): software must not run at a higher privilege level than the user running it.
- AC-6(9): log the use of privileged functions.
- AC-6(10): prevent non-privileged users from executing privileged functions.
Least privilege on Windows: standard user and UAC
Microsoft's documentation recommends making your everyday account a standard user. Even if you stay an administrator, User Account Control applies the principle for you: when an administrator signs in, Windows creates two access tokens, a standard one with the administrative privileges removed and a full administrator one. Explorer and everything you launch from it run with the standard token until you approve an elevation prompt.
You can see which token a window is using. In a normal (not elevated) Command Prompt or PowerShell:
whoami /priv
whoami /groups | findstr "Mandatory"
Example output from a non-elevated prompt on Windows 11:
Privilege Name Description State
============================= ==================================== ========
SeShutdownPrivilege Shut down the system Disabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
SeUndockPrivilege Remove computer from docking station Disabled
SeIncreaseWorkingSetPrivilege Increase a process working set Disabled
SeTimeZonePrivilege Change the time zone Disabled
Mandatory Label\Medium Mandatory Level Label S-1-16-8192
Five privileges and a Medium integrity level: this is the standard token. Run the same commands in a window opened with "Run as administrator" and the list of privileges is much longer, because that window holds the full administrator token. Only open an elevated window for the task that needs it, then close it.
Least privilege on Linux: sudo rules and service users
Log in as a normal user and use sudo for individual commands rather than working in a root shell. You can go further and grant only specific commands. A sudoers rule like this, added with visudo, lets the deploy user restart one service and nothing else:
deploy ALL=(root) /usr/bin/systemctl restart myapp.service
For how to edit sudoers safely, see how to add a user to sudoers.
Services should run as their own dedicated account that owns only the files it needs, not as root. A systemd unit does this with two lines in the [Service] section:
[Service]
User=myapp
Group=myapp
Then tighten file modes so other accounts cannot read the service's secrets, for example chmod 600 on a config file holding a password. Linux file permissions explained covers the numbers.
Least privilege in Docker containers
Unless the image sets a different user, the process in a container runs as root. Docker's own build guidance is: "If a service can run without privileges, use USER to change to a non-root user." In a Dockerfile:
RUN groupadd -r app && useradd --no-log-init -r -g app app
USER app
Everything after the USER line, including the container's main process, runs as app. More on Dockerfiles in how to write a Dockerfile.
Least privilege for databases
Give each application its own database role with only the rights its queries use. In PostgreSQL:
CREATE ROLE app_user LOGIN PASSWORD 'from-your-secret-store';
GRANT CONNECT ON DATABASE shop TO app_user;
GRANT USAGE ON SCHEMA public TO app_user;
GRANT SELECT, INSERT, UPDATE ON orders, customers TO app_user;
This role cannot DELETE, DROP or ALTER anything, cannot read tables you did not list, and cannot create other roles. Run migrations with a separate, more powerful role that the running application never sees. This does not prevent SQL injection, but it caps what an injection can do.
Least privilege in AWS IAM and other cloud platforms
AWS's IAM best practices tell you to "grant only the permissions required to perform a task" by defining "the actions that can be taken on specific resources under specific conditions." A policy that lets an app upload to one bucket, and only that:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::example-uploads/*"
}]
}
AWS accepts that you may start broad while working out what a workload needs. Two built-in tools help you shrink it afterwards: IAM Access Analyzer can generate a policy from the actions a role actually used, as recorded in CloudTrail, and "last accessed information" shows permissions and credentials nobody has used, so you can remove them. Google Cloud and Azure have equivalent role and policy systems; the principle maps the same way.
Common mistakes
- Granting admin "just to get it working". Temporary broad access tends to become permanent. If you must, note what was granted and remove it once the real permission set is known.
- Shared accounts. When five people use one admin login, you cannot remove one person's access or tell from the logs who did what.
- Long-lived keys with wide scope. A token that never expires and can do everything is the worst case if it leaks. Prefer short-lived credentials and narrow scopes.
- Never reviewing. Permissions only ever get added unless someone removes them. Put a recurring review on the calendar.
- Making it so painful people work around it. If getting a needed permission takes a week, people share credentials instead. A fast, logged way to get temporary elevated access is part of a working least-privilege setup.
Frequently asked questions
- What is an example of least privilege?
- A web application connects to its database with an account that can only SELECT, INSERT and UPDATE the tables it uses, instead of the database superuser. If an attacker finds a SQL injection bug, they get those table rights, not the ability to drop the database, read other databases or create new admin users.
- What is the difference between least privilege and zero trust?
- Least privilege is about how much access an identity has: only what its task needs. Zero trust is a broader architecture that also says no request is trusted because of where it comes from, so every request is authenticated and authorised. Least privilege is one of the building blocks of a zero-trust design.
- What is privilege creep?
- Privilege creep is the slow build-up of access that nobody removes: a person changes teams and keeps the old team's permissions, or a temporary admin grant becomes permanent. Periodic access reviews, which NIST lists as control enhancement AC-6(7), exist to catch it.
- Does least privilege apply to programs, or only to people?
- Both. The NIST definition explicitly covers processes acting on behalf of users, and Saltzer and Schroeder's original 1975 wording was that every program and every user should run with the least set of privileges necessary. Services, containers, API keys and CI pipelines all fall under it.
Sources
- NIST CSRC Glossary: least privilege
- NIST SP 800-53 Rev. 5: Security and Privacy Controls (AC-6 Least Privilege)
- Saltzer and Schroeder (1975): The Protection of Information in Computer Systems
- Microsoft Learn: How User Account Control works
- AWS IAM User Guide: Security best practices in IAM
- Docker Docs: Building best practices (USER)
- PostgreSQL Documentation: GRANT