Linux Privilege Escalation: Risks, Hardening, Detection
Linux privilege escalation for defenders: sudo, SUID, kernel CVEs, writable scripts and containers, with hardening steps and auditd detection rules.
Privilege escalation on Linux is when a user or process gains rights it was never granted, usually going from a normal account or service to root. It matters because most serious intrusions need root to persist, read secrets or move to other hosts. Defenders block it with patching, tight sudo rules, few SUID files, mandatory access control and audit logging.
This guide is written for system administrators and DevOps engineers who need to harden and monitor Linux servers. It explains the weakness classes attackers look for, how to find them on your own systems first, and how to detect attempts. It does not contain attack steps. For the wider hardening baseline, start with our RHEL 10 hardening guide, part of the Linux and RHEL 10 learning path.
Key takeaways
- There are two kinds: vertical (normal user to root) and horizontal (one user to another user at the same level, often to reach that user's data or keys).
- Most escalation paths come from configuration, not exotic bugs: broad sudo rules, unneeded SUID binaries, writable scripts run by root, weak file permissions and exposed container sockets.
- Unpatched kernels and setuid helpers remain a real risk. Dirty COW (CVE-2016-5195), PwnKit (CVE-2021-4034), Dirty Pipe (CVE-2022-0847) and Looney Tunables (CVE-2023-4911) are well-known examples, all fixed by vendor updates.
- SELinux or AppArmor in enforcing mode limits what a compromised service can reach even if it gains extra rights.
- auditd rules on sudoers, passwd, shadow and setuid execution give you the evidence to detect and investigate attempts.
- Audit your own systems on a schedule with approved tools and benchmarks such as CIS and the DISA STIG, and only with written authorisation.
Vertical and horizontal escalation
| Type | What changes | Example risk | Main defence |
|---|---|---|---|
| Vertical | Unprivileged account or service gains root or kernel-level control | A web app account abuses a broad sudo rule | Least-privilege sudo, patching, MAC policies |
| Horizontal | One account acts as another account with the same level of rights | Reading another user's SSH private key from a world-readable home directory | Correct home and key permissions, separate service accounts |
Horizontal moves often come first. An attacker who lands as www-data may move to a deploy user that has more sudo rights, then go vertical from there. That is why service account design matters as much as root protection.
Why it matters for DevOps teams
Initial access to a Linux server usually comes through an application flaw, a leaked credential or an exposed service, and it normally lands with limited rights. Root lets an intruder install persistence, disable logging, read every secret on the host (cloud credentials, CI tokens, database passwords) and pivot. On a build agent or Kubernetes node, root can mean access to every workload that runs there. Shrinking escalation paths turns a contained incident into one you can clean up in hours instead of rebuilding the fleet.
The weakness classes to look for
Each class below describes the risk and what to check on your own systems. These are the same categories covered by the CIS Benchmarks and the MITRE ATT&CK technique "Abuse Elevation Control Mechanism" (T1548).
1. Overly broad sudo rules
Risk: rules such as ALL=(ALL) NOPASSWD: ALL for service accounts, or rules that allow editors, interpreters, pagers, package managers or file copy tools. Many such programs can start a shell or write any file, so granting them through sudo is effectively granting root. Wildcards in command arguments widen the risk further.
Harden: grant specific commands with full paths and fixed arguments, require passwords for humans, use sudoedit instead of granting an editor, keep rules in /etc/sudoers.d/ files edited with visudo, and review them like code. Our post on securing sudo access for privileged users covers rule design in detail.
# Review what each account may run (as an administrator)
sudo -l -U deploy
# Validate sudoers syntax before it locks you out
sudo visudo -c
2. Unneeded SUID and SGID binaries
Risk: a file with the setuid bit runs with its owner's rights, which for most such files is root. Every extra setuid binary is extra attack surface, and a setuid copy of a general-purpose tool is a direct path to root. See SUID, SGID and sticky bits explained for how the bits work.
Harden: keep a baseline list from a clean build, compare it regularly, remove the bit where it is not needed, and mount data partitions such as /tmp, /home and /var/tmp with nosuid.
# Inventory setuid and setgid files on local filesystems
sudo find / -xdev -type f \( -perm -4000 -o -perm -2000 \) -exec ls -l {} \; 2>/dev/null \
| sort > /root/suid-baseline-$(date +%F).txt
# Compare against the previous baseline
diff /root/suid-baseline-2026-10-01.txt /root/suid-baseline-$(date +%F).txt
3. Unpatched kernel and setuid helpers
Risk: local privilege escalation bugs in the kernel or in setuid programs such as pkexec and the glibc dynamic loader appear every year. Public proof-of-concept code often follows soon after disclosure.
| CVE | Common name | Component | Fix |
|---|---|---|---|
| CVE-2016-5195 | Dirty COW | Linux kernel memory subsystem | Kernel update |
| CVE-2021-4034 | PwnKit | polkit pkexec | polkit update |
| CVE-2022-0847 | Dirty Pipe | Linux kernel pipe handling | Kernel update |
| CVE-2023-4911 | Looney Tunables | glibc dynamic loader | glibc update |
Harden: apply security errata promptly, reboot or use live patching (for example kpatch on RHEL) so the running kernel is actually the fixed one, and track your fleet against the CISA Known Exploited Vulnerabilities catalogue.
# RHEL family: list pending security updates
sudo dnf updateinfo list --security
# Check whether the running kernel matches the newest installed one
uname -r
rpm -q kernel --last | head -3
4. Writable files and scripts run by root
Risk: cron jobs, systemd units, backup scripts or init hooks that root executes but a less trusted user can modify. The same applies to directories in root's PATH that others can write to, and to scripts that call commands without full paths.
Harden: root-run scripts and their directories should be owned by root and not group or world writable. Use absolute paths in cron entries and scripts, and set a fixed PATH at the top of crontabs.
# World-writable files outside /proc, /sys and temp dirs
sudo find / -xdev -type f -perm -0002 ! -path "/proc/*" ! -path "/sys/*" 2>/dev/null
# Check ownership and modes of cron and systemd locations
ls -la /etc/cron* /etc/systemd/system
5. Weak permissions on sensitive files
Risk: readable /etc/shadow, private keys with loose modes, credentials in world-readable config files or shell history, and backup copies of sensitive files left in readable places. Our guide to the /etc/shadow file lists the correct permissions.
Harden: check modes on shadow, gshadow, sudoers and SSH host keys; keep application secrets in a secrets manager instead of files; and make home directories 0700 or 0750.
6. Linux capabilities granted too widely
Risk: file capabilities split root's power into pieces, but some pieces such as cap_sys_admin, cap_dac_override or cap_setuid are close to full root.
Harden: list files with capabilities using getcap -r / 2>/dev/null, keep only what packages ship, and in systemd units use CapabilityBoundingSet= and NoNewPrivileges=yes.
7. Container and orchestration paths
Risk: membership of the docker group, a mounted /var/run/docker.sock, privileged containers, hostPath mounts of sensitive directories and containers running as root all give a path from container to host root.
Harden: treat the docker group as root-equivalent, never mount the runtime socket into workloads, run containers as non-root with dropped capabilities, and enforce the Kubernetes Pod Security Standards "restricted" profile where you can. More in 10 golden rules of Docker container hardening.
Mandatory access control: SELinux and AppArmor
Discretionary permissions decide what a user can do. SELinux and AppArmor add a second policy that confines what a program can do, regardless of the user it runs as. A web server confined by SELinux cannot read home directories or open arbitrary network ports even if an attacker controls it. Keep SELinux in enforcing mode on RHEL and fix denials with booleans or proper file contexts instead of disabling it. Our SELinux in RHEL 10 guide walks through modes, contexts and troubleshooting.
getenforce
sudo ausearch -m AVC -ts recent
Detection: what to log and alert on
Prevention fails sometimes, so you need records. On RHEL and most distributions, auditd is the standard source. Rules like these watch the files and actions that matter most:
## /etc/audit/rules.d/50-privesc.rules
-w /etc/sudoers -p wa -k sudoers_change
-w /etc/sudoers.d/ -p wa -k sudoers_change
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /etc/group -p wa -k identity
-a always,exit -F arch=b64 -S execve -C uid!=euid -F euid=0 -k setuid_exec
-a always,exit -F arch=b64 -S setuid,setgid,setreuid,setregid -F auid>=1000 -F auid!=unset -k id_change
Load them with sudo augenrules --load and search with ausearch -k sudoers_change. Setup details are in how to enable and configure auditd in RHEL 10.
Other useful signals:
- Failed and unusual sudo use in
/var/log/secureor the journal (journalctl _COMM=sudo). - New setuid files compared with your baseline.
- File integrity changes reported by AIDE on binaries, configs and cron directories.
- New kernel modules loaded outside maintenance windows.
- Processes running as root whose parent is a web server or other service account.
Ship these logs off the host to a SIEM or central log store, because an intruder with root can edit local files.
Auditing your own systems
Run regular, authorised assessments against a written baseline. Practical options:
- OpenSCAP with the SCAP Security Guide to check RHEL systems against CIS or DISA STIG profiles and produce a report.
- Lynis, an open-source host auditing tool that flags weak configuration and gives hardening suggestions.
- Your vulnerability scanner for missing patches across the fleet.
- Authorised penetration tests with a signed scope, so findings are tested by professionals rather than discovered by intruders.
# Example: CIS profile scan on RHEL 10 with OpenSCAP
sudo dnf install -y openscap-scanner scap-security-guide
sudo oscap xccdf eval --profile cis_server_l1 \
--report /root/cis-report.html \
/usr/share/xml/scap/ssg/content/ssg-rhel10-ds.xml
Check the profile IDs shipped with your SCAP Security Guide version using oscap info on the datastream before running the scan.
Hardening checklist
| Area | Control | How to verify |
|---|---|---|
| Patching | Security errata applied, running kernel current | dnf updateinfo, uname -r |
| sudo | Specific commands only, no NOPASSWD ALL for services | sudo -l -U <user>, review sudoers.d |
| SUID/SGID | Baseline list, nosuid on data mounts | Scheduled find diff, findmnt |
| File permissions | No writable root-run scripts, correct shadow modes | World-writable search, stat |
| MAC | SELinux or AppArmor enforcing | getenforce, aa-status |
| Services | NoNewPrivileges, capability bounding, dedicated users | systemd-analyze security |
| Containers | Non-root, no runtime socket mounts, no privileged pods | Admission policy reports |
| Logging | auditd rules, central log shipping, AIDE | auditctl -l, SIEM dashboards |
Linux security and administration are core modules of our RHCSA training, run in Kharadi, Pune and live online.
FAQs
What is privilege escalation in Linux?
It is gaining rights beyond those an account or process was given, most often moving from a normal user or service account to root. It usually follows an initial compromise and lets an intruder take full control of the host.
What is the difference between vertical and horizontal privilege escalation?
Vertical escalation raises the level of access, for example from a user to root. Horizontal escalation moves sideways to another account with similar rights, often to reach its data, keys or sudo rules.
What causes most Linux privilege escalation risk?
Configuration mistakes: broad sudo rules, unnecessary SUID binaries, root-run scripts that others can edit, weak file permissions and exposed container sockets. Missing kernel and package updates are the other big source.
How do I find SUID files on my servers?
Run find / -xdev -type f -perm -4000 as an administrator, save the output as a baseline from a clean build, and compare it on a schedule. Remove the bit from anything that does not need it.
Does SELinux stop privilege escalation?
It does not fix the underlying bug, but it confines what a compromised program can access, which often blocks the next step. Keep it enforcing and fix denials properly rather than disabling it.
Which logs help detect privilege escalation attempts?
auditd records for changes to sudoers, passwd and shadow and for setuid executions, sudo entries in the secure log or journal, AIDE integrity reports and new kernel module loads. Send them to a central system.
Is testing for privilege escalation legal?
Only on systems you own or have written permission to test. Use approved scanners and benchmarks on your own infrastructure, and hire authorised testers for deeper assessments.
How often should I audit for privilege escalation paths?
Continuously for patches and logs, and at least monthly or after every major change for sudo rules, SUID baselines and permissions. Automate the checks with OpenSCAP or configuration management.
References
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0