On Unix and Linux, privilege is concentrated in one account, root, and reached through a tangle of shared passwords, sudo rules and SSH keys that most privileged access programmes never fully map. PAM programmes are often designed around Windows and Active Directory, then extended to Linux by vaulting the root password and stopping there. That leaves the real access paths (personal and automation SSH keys, broad sudo rules, local accounts outside the directory) ungoverned. This guide sets out how to govern root, how to bridge Linux and Unix hosts to Active Directory, how to design sudo and SSH access so privilege is scoped and attributable, how to record and review privileged sessions, and how to measure progress. It is for identity, PAM and Linux platform teams. The general programme is covered in the Privileged Access Management Guide; this page goes deeper on the Unix specifics.
Key takeaways
- Govern the paths, not just the password: root is reached through su, sudo, SSH keys, certificates and automation, and each path needs an owner and a control.
- Bridge identities to the directory with SSSD and realmd (or an equivalent bridging product) so people log in as named accounts and leavers lose access everywhere at once.
- Scope sudo to commands, require authentication, and send sudo event and I/O logs to a central log server; a rule that allows an editor or shell is a rule that allows root.
- Replace static SSH keys with short-lived certificates or vault-brokered access where you can, and inventory every
authorized_keysfile where you cannot. - Automation is the largest privileged population: configuration management, backup and monitoring accounts usually hold unrestricted root keys and should be scoped and rotated first.
How Unix privilege differs from Windows
| Aspect | Windows and Active Directory | Unix and Linux | Consequence for PAM |
|---|---|---|---|
| Privileged identity | Many groups and rights (Domain Admins, local Administrators, user rights) | UID 0 bypasses discretionary access checks; delegation through sudo, capabilities and group membership | Least privilege lives in sudo rules and service design rather than built-in roles |
| Accounts | Mostly in the directory | Local /etc/passwd accounts plus optional directory accounts | Local accounts escape joiner, mover and leaver processes |
| Remote access | RDP, WinRM, Kerberos | SSH with passwords, keys, certificates or Kerberos (GSSAPI) | SSH keys are credentials the directory does not see |
| Credential storage | LSASS, credential manager | /etc/shadow, ~/.ssh, keytabs, configuration files | Discovery must scan files, not just directory objects |
| Native logging | Security event log | auth or secure log, journald, auditd, sudo logs | Logging must be configured and forwarded deliberately |
The result is that Linux privileged access is distributed and file-based. Discovery is the first job: list every account with UID 0, every member of wheel or sudo groups, every sudoers rule (including /etc/sudoers.d/ and any LDAP or SSSD-delivered rules), every authorized_keys file and every keytab. The Privileged Account Discovery and Onboarding Guide covers the process.
Governing root
- No interactive root logins: set
PermitRootLogin noinsshd_config. OpenSSH's default isprohibit-password, which still allows root with a key, so the default is not enough. Where a tool genuinely needs root over SSH, useforced-commands-onlywith a key restricted to one command. - Unique root password per host, vaulted: the root password is for console and single-user recovery. Store it in a vault with check-out, rotate it after use, and never share one root password across a fleet. See the Linux PAM Guide for the authentication stack that protects it.
- Restrict su: limit
suto the wheel group through PAM (pam_wheel), or remove its use entirely in favour of sudo, which logs who ran what. - Only one UID 0: alert on any additional account with UID 0, a classic persistence technique. ATT&CK tracks account changes under T1098 Account Manipulation and local account abuse under T1078.003.
- Break-glass procedure: document how to reach root when the directory, vault or network is down, test it, and alert whenever it is used.
Bridging Unix and Linux to Active Directory
Directory bridging lets people sign in to Linux hosts with their AD account, so access follows the identity lifecycle. On modern Linux the common open source route is realmd for enrolment and SSSD for identity, authentication and access control; commercial bridging products add central policy and support for older Unix platforms.
| Function | SSSD and realmd setting | Notes |
|---|---|---|
| Join the domain | realm discover, realm join AD.EXAMPLE.COM | Creates the host's computer account and keytab; can target a specific OU or use a one-time password |
| Identity and authentication | id_provider = ad | Kerberos authentication against domain controllers; automatic ID mapping by default, or POSIX attributes from AD |
| Who may log in | access_provider = simple (via realm permit), ad (GPO-based) or ad_access_filter | Restrict each host or host group to named AD groups; never leave access open to all domain users |
| Privilege | sudo rules in sudoers files, or delivered centrally through LDAP or SSSD | Grant sudo to AD groups, not individuals |
| Offline behaviour | SSSD credential cache | Cached logins keep working if domain controllers are unreachable; cache lifetime is a security decision |
- Separate admin identities: map Linux privilege to dedicated AD admin accounts (for example a separate admin account per engineer), not to everyday accounts used for email and browsing.
- Protect the host keytab: the keytab created by the join lets the host authenticate as its computer account. It must be readable only by root. See the Linux Service Accounts and Keytab Management Guide.
- Know the dependency: bridging moves the trust anchor to Active Directory. If AD is compromised, so are bridged hosts, so keep break-glass local access independent of AD.
The SSSD and Linux Active Directory Integration Guide covers configuration in detail.
Designing sudo for least privilege
sudo is the main privilege delegation tool on Linux, and the sudoers policy language is powerful enough to be dangerous. Key options from the sudoers manual:
| Option or tag | Default | Use |
|---|---|---|
authenticate / NOPASSWD | Authentication required | Keep authentication on for people; use NOPASSWD only for tightly scoped automation commands |
timestamp_timeout | 5 minutes | Shorten for high-risk hosts; set to 0 to require a password every time |
env_reset, secure_path | env_reset on | Run commands in a minimal environment with a controlled PATH |
NOEXEC tag | Off | Stops permitted programs such as pagers and editors spawning further commands (needs OS support) |
INTERCEPT tag | Off | Checks and logs programs started by the permitted command (sudo 1.9.8 and later) |
sudoedit | Built in | Lets users edit specific files without running an editor as root |
Command digests (sha256:) | None | Runs a command only if its hash matches, so a replaced binary is refused |
log_input, log_output | Off | Record keystrokes and terminal output of sudo sessions |
log_servers | None | Send event and I/O logs to a central sudo_logsrvd server (sudo 1.9 and later) |
- Use command aliases per role: define
Cmnd_Aliassets for each job (restart a service, read logs, manage packages) and grant those to AD groups. - Avoid escape-prone commands: rules allowing
vi,less,find, interpreters,taror wildcards in arguments usually give a full root shell. ATT&CK tracks abuse of sudo under T1548.003 Sudo and Sudo Caching. - Review "ALL" rules:
ALL=(ALL) ALLis equivalent to root. Keep it to a small admin group, with authentication and logging. - Manage sudoers centrally: deploy rules through configuration management or central LDAP/SSSD delivery, validate with
visudo -c, and treat changes as privileged changes.
The sudo and sudoers Security Guide covers rule review techniques.
SSH access: keys, certificates and brokered sessions
| Approach | How it works | Strengths | Weaknesses | Best fit |
|---|---|---|---|---|
| Static public keys | Keys listed in ~/.ssh/authorized_keys | Simple, universal | Never expire, copied freely, invisible to the directory | Small estates with strict inventory |
| Central key lookup | AuthorizedKeysCommand fetches keys from a directory | Keys follow the identity lifecycle | Still long-lived keys; lookup service is critical | Directory-integrated estates |
| SSH certificates | Hosts trust a CA via TrustedUserCAKeys; users get short-lived signed certificates | Expiry built in, principals map to roles, no per-host key distribution | CA key is a crown jewel; needs issuance tooling | Medium and large estates |
| PAM proxy or broker | Users connect through a gateway that injects vaulted credentials and records sessions | Recording, approvals, no credential exposure to users | Single point of failure; latency; tool cost | Regulated environments, third-party access |
| Kerberos (GSSAPI) | Domain tickets via GSSAPIAuthentication | No keys on disk, AD lifecycle | Depends on AD and DNS; less common for automation | AD-bridged estates |
- Certificates in practice: sign with
ssh-keygen -s ca_key -I key_id -n principals -V +8h user_key.pub. The-Ikey identifier is logged by sshd whenever the certificate is used, which gives attribution. Restrict with-O source-address=and-O no-port-forwarding, and with hardware-backed keys (ed25519-sk) addverify-required. UseAuthorizedPrincipalsFileto map principals such asdb-adminto accounts. - Revocation: distribute a Key Revocation List (
ssh-keygen -k) throughRevokedKeys. Note that if that file is unreadable, sshd refuses public key authentication for all users, so deploy it carefully. - Restrict who can log in: use
AllowGroupsandMatchblocks, setPasswordAuthentication no(the OpenSSH default is yes), and useAuthenticationMethods publickey,keyboard-interactivewhere a second factor is required. - Protect private keys at the source: keys on developer laptops are a target. In the PyTorch torchtriton supply chain attack a malicious package copied SSH keys from
~/.sshalong with other secrets. Short-lived certificates and hardware-backed keys limit what a stolen file is worth. See the SSH Key Management Guide.
Session control and recording
- sudo I/O logging:
log_inputandlog_outputrecord what was typed and displayed during sudo sessions, replayable withsudoreplay. Send them tosudo_logsrvdwithlog_serversso a root user on the host cannot delete them; sudo_logsrvd stores I/O logs under/var/log/sudo-ioby default, supports TLS and can relay to another server. - Whole-session recording: terminal session recorders (for example tlog on RHEL) or a PAM proxy capture full SSH sessions, not just sudo commands. Use them for third-party access and for the highest-risk systems, and tell users that sessions are recorded.
- auditd for root activity: an execve rule for effective UID 0 records every root command regardless of how root was reached. See the Linux Logging and auditd for Defenders Guide.
- Just-in-time elevation: grant sudo group membership or certificate principals for a time window after approval, rather than standing membership. Short certificate validity (hours) is the simplest JIT mechanism on Linux.
The Privileged Session Management Guide compares recording approaches.
Automation and service accounts
Configuration management (Ansible, Puppet, Chef, Salt), backup agents, monitoring, deployment pipelines and vulnerability scanners all need privileged access to Linux, and they usually have more of it than any person.
- One identity per tool: separate accounts for each tool and environment, never a shared "automation" account with the same key everywhere.
- Scoped sudo with NOPASSWD only where needed: limit automation accounts to the commands they run, with command digests where practical.
- Restricted keys: prefix automation keys in
authorized_keyswithfrom="10.0.5.0/24",command=andno-port-forwarding, or issue short-lived certificates from the pipeline at run time. - Vault and rotate: keep automation private keys and passwords in a secrets manager, rotate them on a schedule and on staff departure, and alert on use from unexpected sources.
- Treat the control node as tier zero: a configuration management server that can run root commands on every host is as sensitive as a domain controller.
Detection and measurement
| Signal | Source | ATT&CK |
|---|---|---|
New entries in any authorized_keys file | File integrity monitoring, auditd watch | T1098.004 |
| sudo use by accounts not in an approved group, or outside change windows | sudo event logs, sudo_logsrvd | T1548.003 |
| Root or service account SSH logins from new sources | sshd logs | T1021.004 |
New UID 0 account or changes to /etc/sudoers.d/ | auditd, file integrity monitoring | T1098 |
Reads of /etc/shadow by unexpected processes | auditd | T1003.008 |
Changes to PAM configuration in /etc/pam.d/ | File integrity monitoring | T1556.003 |
Metrics: percentage of Linux hosts bridged to the directory with group-restricted login; number of sudo rules granting ALL outside the admin group (target zero); number of static keys in authorized_keys without a recorded owner (target zero); percentage of privileged SSH access using certificates or a broker; percentage of root passwords unique and vaulted; and time to remove a leaver's access from all Linux hosts.
Rolling it out
- Discover: collect accounts, sudoers, keys and keytabs from every host with a read-only script or your PAM tool's discovery.
- Quick wins: disable root SSH login, vault and randomise root passwords, remove leavers' keys.
- Bridge: join hosts to the directory in rings (non-production, then production), restricting login to named groups.
- Rewrite sudo: convert ad hoc rules to role-based command aliases granted to directory groups; run the new policy alongside the old one on a pilot group first, and keep the previous sudoers in configuration management for rollback.
- Centralise logs: forward sudo, sshd and auditd logs and set up sudo_logsrvd.
- Move to certificates or a broker: start with administrators, then automation; remove static keys once certificate access is proven.
A small team with a few dozen servers can get far with SSSD, a curated sudoers set and certificates from a simple CA. Large estates with legacy Unix (AIX, Solaris, HP-UX) and third-party access usually need a commercial bridging or PAM product for coverage and session recording.
Common failure patterns
- Vault the root password and declare victory: nobody uses the root password; they use keys and sudo, which remain unmanaged.
- One automation key everywhere: a single private key with root on every host, stored on a build server and several laptops.
- sudo rules that are really root: editor, pager, interpreter or wildcard rules that give a shell.
- Directory bridging with open access: hosts joined to AD without access rules, so every domain user can log in.
- Local logs only: sudo and auth logs kept on the host, where an attacker with root deletes them.
- Leavers keep keys: the AD account is disabled but the person's key remains in
authorized_keyson dozens of hosts.
Framework mapping
| Control | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | CIS Controls v8.1 | ISO/IEC 27001:2022 Annex A |
|---|---|---|---|---|
| Privileged account inventory and lifecycle | AC-2 | PR.AA-01 | 5.1, 5.4 | A.5.16, A.5.18 |
| Least privilege through sudo | AC-6, AC-6(5) | PR.AA-05 | 6.8 | A.8.2 |
| Strong authentication for admins | IA-2, IA-5 | PR.AA-01 | 6.5 | A.8.5 |
| Session logging and recording | AU-2, AU-12 | DE.CM-01 | 8.2 | A.8.15 |
Practitioner checklist
- Discover every UID 0 account, sudoers rule, authorized_keys file and keytab across the estate.
- Set PermitRootLogin no and PasswordAuthentication no, and restrict SSH with AllowGroups.
- Give each host a unique, vaulted root password and test the break-glass procedure.
- Bridge hosts to the directory and restrict login on each host to named groups.
- Rewrite sudo as role-based command aliases granted to directory groups, with authentication and no shell-escape commands.
- Send sudo event and I/O logs to sudo_logsrvd and forward sshd and auditd logs to the SIEM.
- Issue short-lived SSH certificates for administrators and automation, and maintain a revocation list.
- Give each automation tool its own restricted identity, stored in a vault and rotated.
- Alert on authorized_keys changes, new UID 0 accounts and sudoers changes.
Standards and references
- Sudo Project: sudoers manual
- Sudo Project: sudo_logsrvd manual
- OpenBSD: sshd_config(5)
- OpenBSD: ssh-keygen(1), certificates and key revocation lists
- SSSD: Active Directory provider
- NIST: SP 800-53 Rev. 5
- MITRE ATT&CK: Sudo and Sudo Caching
- MITRE ATT&CK: SSH Authorized Keys
Related NHI Mgmt Group resources: Privileged Access Management Guide · sudo and sudoers Security Guide · SSH Key Management Guide · SSSD and Linux Active Directory Integration Guide