doas is a minimal privilege escalation utility that lets an authorized user run a command as another user, most often as root, according to rules in the file /etc/doas.conf. It originated in OpenBSD in 2015 as a deliberately small replacement for sudo, and on Linux it is available mainly through the OpenDoas port, which Alpine Linux and several other distributions package.
In terms of Linux permissions, doas fills the same role as sudo: it is a setuid root program that checks who is calling, consults its rules, authenticates the user and then executes the requested command with the target user identifier. Its defining property is simplicity by design, which reduces the code that runs with full privileges and therefore the attack surface.
How doas grants elevated privileges
doas works by being installed with the setuid bit owned by root, so it starts with root privileges regardless of who runs it. It then reads /etc/doas.conf, finds the rule that applies to the calling user, the target user and the requested command, and either refuses, asks for a password or executes the command directly.
Authentication uses the caller’s own password, not the root password, which is the same model as sudo and the opposite of su. On Linux, OpenDoas can authenticate through PAM or through the shadow password file, depending on how it was built. After success, doas sets the user and group identifiers, prepares a reduced environment and replaces itself with the target command.
The basic invocation is doas command, while doas -u postgres psql runs a command as a non-root user and doas -s starts a shell. The option -n makes doas fail instead of prompting, which is useful in scripts, and -L clears a remembered authentication before the timeout expires.
The doas.conf rule syntax
Every line of doas.conf is a rule in a fixed grammar: an action, optional options, an identity, an optional target user and an optional command with arguments. Identities are user names or group names prefixed with a colon, such as :wheel. The most important evaluation rule is that the last matching rule wins, so specific rules belong after general ones.
The following table explains the elements of a rule.
| Element | Meaning | Example |
|---|---|---|
| permit or deny | Allows or forbids the matching request | permit :wheel |
| Identity | A user name or a group prefixed with a colon | alice or :admin |
| as target | Restricts which user may be assumed | permit bob as postgres |
| cmd command | Restricts the rule to one command | cmd systemctl |
| args list | Restricts exact arguments; empty means none | args restart nginx |
Options modify how a permitted rule behaves. The table lists the options supported by OpenBSD doas and OpenDoas.
| Option | Effect | Security consideration |
|---|---|---|
| nopass | Runs without asking for a password | Use only for narrowly restricted commands |
| persist | Remembers authentication for a short period | Convenient, but extends the window of misuse |
| keepenv | Keeps the caller’s environment variables | Can pass unsafe variables to root |
| setenv { } | Sets or removes specific variables | Safer than keeping the full environment |
| nolog | Suppresses logging of the execution | Reduces the audit trail |
A typical workstation configuration is a single line, permit persist :wheel, while a server may add permit nopass backup as root cmd /usr/local/bin/backup.sh for an automated task. A configuration file can be validated with doas -C /etc/doas.conf, which reports syntax errors and, given a command, shows which rule would match.
doas compared with sudo and su
doas differs from sudo mainly in scope and complexity: sudo supports host aliases, command aliases, LDAP-backed policies, plugins, session recording and detailed per-command defaults, whereas doas supports only the small rule set described above. Its source code is a small fraction of the size of sudo, which makes it easier to audit.
| Property | doas | sudo | su |
|---|---|---|---|
| Password requested | Caller’s password | Caller’s password | Target user’s password |
| Configuration file | /etc/doas.conf | /etc/sudoers, edited with visudo | None, uses PAM |
| Per-command rules | Yes, with exact arguments | Yes, with wildcards and aliases | No |
| Central policy and plugins | No | Yes, including LDAP and plugins | No |
| Default on major distributions | Alpine and some minimal systems | Most Debian, Ubuntu and Fedora systems | Universally available |
polkit addresses a different problem: it authorizes specific actions requested over D-Bus by desktop services, not arbitrary command execution, so it complements doas rather than replacing it.
Choosing and deploying doas
doas is a good choice for small, single-administrator systems, containers, embedded devices and minimal distributions where sudo’s features are unused. It is a weaker fit for organizations that need centralized policy, detailed audit logs or integration with directory services.
The decision table summarizes typical situations.
| Situation | Recommended tool | Reason |
|---|---|---|
| Personal Alpine or Arch workstation | doas | Simple rules cover all needs |
| Minimal container image needing root steps | doas or no escalation | Smaller code and fewer dependencies |
| Enterprise fleet with LDAP accounts | sudo | Central policy and session recording |
| Desktop actions such as mounting drives | polkit | Fine-grained authorization for services |
When migrating, administrators should keep a working root path until the new configuration is tested, for example an open root session or console access. The config file should be owned by root and set to mode 0400 or 0600, because a world-writable rule file would let any user grant themselves root.
Limitations and common mistakes
- Rule order errors: a broad
denyplaced after a specificpermitsilently overrides it, because the last match wins. - Overusing nopass: a passwordless rule without
cmdeffectively gives the account unrestricted root access. - Assuming sudo compatibility: scripts that call sudo options such as
-Eor rely on sudoers defaults need adjustment. - Persist differences on Linux: OpenDoas implements persist with timestamp files, and some builds disable it, so behavior can differ from OpenBSD.
- Limited logging: doas logs to syslog but offers no session recording, which may not meet compliance requirements.
Put simply
doas is like a short guest list at the door of the administrator’s room. The list says who may go in and, if needed, exactly what they may do there. A person on the list confirms their identity with their own password, and the door opens.
The list is short and easy to read, which is the point. Fewer rules mean fewer mistakes, and a smaller program means fewer places where something can go wrong.
In practice
A developer runs a small home server on Alpine Linux with two accounts: her own and a service account called backup. She installs doas and writes a two-line configuration. The first rule, permit persist :wheel, lets her administer the system after entering her password once every few minutes.
The second rule, permit nopass backup as root cmd /usr/local/bin/snapshot.sh, lets the nightly backup job run exactly one script as root without a password. She checks both rules with doas -C /etc/doas.conf before logging out. The result is a configuration she can read in five seconds, and a compromised backup account still cannot open a root shell, because no rule permits anything except that single script.