Fact-checked by Grok 2 weeks ago

doas

Doas is a lightweight command-line utility in Unix-like operating systems that enables a user to execute commands as another user, typically the (), after via password or other configured methods. Originally developed for , doas provides a simpler and more minimalistic alternative to the widely used tool, with a smaller that enhances auditability and reduces potential security vulnerabilities. Introduced in 5.8 in October 2015 by developer Ted Unangst, it addresses concerns over sudo's complexity by offering straightforward syntax and configuration while maintaining essential functionality. The utility operates by parsing rules defined in a , usually /etc/doas.conf, which specifies permissions such as allowing certain users to run commands as or others without repeated . Key features include support for non-interactive modes, environment variable inheritance (like DISPLAY and TERM for graphical applications), and options to persist or check configuration validity without execution. Unlike , doas does not preserve the entire user environment by default, instead setting variables like HOME and SHELL to those of the target user to promote through isolation. It has been praised for its efficiency in resource-constrained environments and is configurable to deny or permit actions based on user, group, or command specifics. Since its inception, doas has gained adoption beyond through community ports and packages, becoming available in major Linux distributions such as (via the opendoas package), , Gentoo, and , as well as in and other BSD variants. These implementations maintain compatibility with the original while adapting to diverse system architectures, including support for , , and even macOS in some forks. Doas's design philosophy emphasizes proactive security and simplicity, aligning with 's broader focus on correctness and minimalism in system tools.

History and Development

Origins and Motivation

In Unix-like systems, has long been facilitated by tools such as and , with the latter originating in 1980 at the at as a means to execute commands as another user, typically , under configurable permissions. Over decades, accumulated extensive features including detailed logging, plugin support, scripting capabilities, and environmental controls, resulting in a significantly larger and more complex than necessary for basic use cases. Within the project, which prioritizes code correctness, minimalism, and proactive security auditing, sudo's growth into a multifaceted utility raised concerns about its maintenance burden and ; developers like and Todd Miller highlighted that its size—approximately five times that of typical setuid binaries—meant excessive code executed in privileged contexts, potentially amplifying vulnerabilities. Ted Unangst, a longtime OpenBSD contributor, developed doas as a direct response to these issues, driven by his own frustrations with sudo's default configuration, particularly its "safe environment" mode that unpredictably altered variables and disrupted routine tasks like package additions or port compilations. He aimed to provide a streamlined alternative that embodied 's core tenets of simplicity and security, avoiding the that had encumbered sudo. Initial proposals and discussions emerged in the community around mid-2015, reflecting broader desires to prune bloated dependencies from the base system while preserving for advanced needs via the ports collection. Unangst's design goals centered on a focused, single-purpose tool for switching to root privileges, deliberately omitting extraneous elements such as humorous insults, complex scripting interfaces, or built-in logging to minimize the codebase and enhance auditability.

Release and Initial Implementation

doas was initially developed by Ted Unangst ([email protected]) as a lightweight alternative to , with the codebase imported into the source tree on July 16, 2015. The implementation, written primarily in C, featured a simple parser generated by and totaled approximately 800 lines of code across its core files (doas.c, env.c, parse.y, and doas.h). This compact design emphasized minimalism, contrasting sharply with sudo's extensive footprint exceeding 200,000 lines. Following its import, doas underwent testing in OpenBSD snapshots, the daily development builds available between releases, allowing early feedback from developers before stabilization. It was released as a standard utility in 5.8 on , 2015, becoming the default tool for and replacing in the base system. The project adopted the , a permissive commonly used in for its brevity and compatibility with BSD traditions. Documentation accompanied the rollout, including the doas(1) detailing usage and the doas.conf(5) specifying configuration syntax, both integrated into the official manual set from the initial release. Contributions from other developers refined the code during the pre-release period, focusing on audits and portability within the base system. This integration aligned with OpenBSD's emphasis on secure-by-default utilities, as outlined in its development philosophy.

Functionality

Purpose and Design Principles

doas is a lightweight utility designed to execute commands with elevated privileges, typically as the user, by allowing configurable permissions for specified s or groups. Its primary purpose is to serve as a streamlined alternative to , enabling secure and controlled in systems, particularly those prioritizing security and minimalism, such as . The design of doas adheres to principles of and to enhance and usability. It eschews complex features like built-in , scripting capabilities, or command aliases, instead relying on a straightforward for and the system's native mechanisms—such as password prompts via /etc/login.conf—for verification. This approach results in a significantly smaller codebase compared to , which reduces the potential by limiting the amount of privileged code executed. By focusing on essential functionality, doas offers advantages including faster execution times and lower , making it suitable for environments where efficiency and reduced complexity are paramount. Its configuration-driven model supports fine-grained permissions without unnecessary overhead, thereby minimizing vulnerabilities associated with feature bloat in more comprehensive tools. doas targets use cases in security-oriented system administration, such as in BSD variants, where administrators require non-interactive or targeted granting for routine tasks like package management or service configuration, without the need for elaborate enforcement.

Basic Usage Mechanics

The doas utility executes a specified command as another user, with the basic syntax given by doas [-Lns] [-a style] [-C config] [-u user] command [arg ...]. The command argument is mandatory unless the -C, -L, or -s options are used, and it allows the user to run programs with elevated privileges after . By default, without the -u option, doas targets the user for execution. At runtime, doas forks a new process to execute the command with the privileges of the target user, preserving the invoking user's current working directory. It constructs a new environment for the subprocess, setting variables such as HOME, LOGNAME, PATH, SHELL, and USER to values appropriate for the target user, while inheriting DISPLAY and TERM from the parent process; the DOAS_USER variable is also set to identify the invoking user. Unless otherwise configured, doas prompts the invoking user for their password to authenticate the request before proceeding, and the process exits upon command completion. For error handling, doas provides clear diagnostic messages, such as indications of permission denials, configuration parsing failures, errors, or issues with command location or executability. It returns an of 0 upon successful execution and a non-zero status greater than 0 for any failure, allowing scripts and calling processes to detect and respond to errors programmatically.

Configuration

Syntax and Directives

The for doas is located at /etc/doas.conf and is parsed line-by-line, with comments introduced by the # character and extending to the end of the line. The core syntax of rules in doas.conf follows the format permit | deny [options] identity [as target] [cmd command [args ...]], where permit allows execution and deny blocks it (though deny is rarely used as unmatched rules default to denial). Here, identity specifies the or group (prefixed with :) initiating the command, target optionally designates the to run as (defaulting to any , including root, if unspecified), and cmd restricts execution to a specific command with optional arguments. Commands must use absolute paths for precision, and wildcards are not supported in command specifications. Key options, or flags, modify rule behavior: nopass exempts the rule from requiring a password prompt, persist caches successful credentials for the duration of the session to avoid repeated prompts, and keepenv preserves specified variables during execution. The target clause explicitly sets the execution , overriding defaults. Rules are evaluated in the order they appear in the file, with the last matching rule determining the outcome; if no rule matches, access is denied, making rule ordering critical for precedence.

Practical Examples

Practical examples of doas configuration demonstrate how administrators can tailor permissions for specific users, groups, and commands in real-world scenarios, such as system monitoring, service management, and user privilege delegation. These configurations are defined in the /etc/doas.conf file, where rules follow a structured syntax to control access without unnecessary overhead. The following annotated examples illustrate common use cases, drawing from established documentation to ensure secure and targeted privilege escalation. One straightforward application allows a designated user to execute a tool as without requiring a , enhancing efficiency for routine diagnostics. For instance, the rule permit nopass user1 as [root](/page/Root) cmd /usr/sbin/procmap enables user1 to run the /usr/sbin/procmap command—useful for process mapping—directly as , bypassing each time. This setup is ideal for trusted administrative tasks where repeated access is needed but risks are minimized by limiting to a single command. For broader administrative access, group-based rules simplify management across multiple users. The configuration permit :wheel as root grants all members of the group full root privileges for any command, allowing them to perform system-wide operations like package or file edits without individual rule definitions. This is commonly used in environments where wheel membership already signifies elevated trust, such as development teams handling server maintenance. In service-oriented setups, particularly on systems with , caching authentication can streamline repeated interactions. The rule permit persist :admins cmd /usr/bin/systemctl permits members of the admins group to manage services via systemctl (e.g., starting or stopping daemons) with a password prompt only on the first use per session, after which access persists until a timeout of 5 minutes (in the implementation). This reduces interruptions during maintenance windows while restricting actions to service control. To support specialized tasks like running scripts in a restricted context, preservation ensures . The example permit keepenv user2 as [nobody](/page/Nobody) allows user2 to execute commands as the nobody user—a low-privilege account for untrusted processes—while retaining key environment variables from the original session, preventing issues with paths or locales. This is particularly useful for operations or sandboxed applications where full environment reset could break functionality. Best practices for doas configurations emphasize precision and verification to maintain security. Always specify exact commands with absolute paths rather than broad permissions to limit exposure, and test rules using non-root accounts via syntax checks like doas -C /etc/doas.conf before deployment. Additionally, set file permissions to 0400 owned by root to prevent unauthorized modifications.

Security Model

Permissions and Authentication

Doas enforces through a -based permissions model defined in the /etc/doas.conf. Rules specify permit or deny directives that match the invoking user's identity (username or group) against the target user and command to be executed, with the last matching taking precedence; if no matches, is denied by . This model evaluates permissions before command execution, allowing fine-grained control such as restricting specific commands or arguments for designated users or groups. Authentication in doas integrates with the host system's mechanisms, such as the on or () on other BSD variants like . By default, doas prompts for the target user's upon invocation unless a rule includes the nopass option, which permits execution without ; doas-specific methods can be configured via an auth-doas entry in /etc/login.conf on to select alternative styles like one-time passwords. For non-root targets, specified via the -u option or as target in rules, similarly verifies the target user's credentials. The persist option in rules enables caching of successful for subsequent invocations within the same session, avoiding repeated prompts; this persists for a default timeout of 5 minutes, after which re-authentication is required. Users can manually clear the cache using doas -L to invalidate persisted credentials before the timeout. In portable implementations, persist behavior may vary due to platform-specific APIs, but it remains configurable per . Doas includes basic of successful command executions to the logger (syslogd) by , but lacks built-in facilities for denial logging; tracking of denied attempts relies on external audit tools such as auditd. The nolog option in rules can disable even this syslog recording for specific permissions. Configuration changes in /etc/doas.conf take effect immediately upon the next invocation, as doas parses the file each time without requiring a restart or reload; the -C option allows syntax validation beforehand.

Key Differences from Sudo

doas emphasizes simplicity and minimalism in its design, lacking many advanced features found in such as command aliases, configurable timeouts, email alerts for usage, and support for plugins or LDAP integration. This reduction in functionality streamlines for basic needs but may limit its suitability for environments requiring granular policy enforcement or auditing beyond logging. The configuration file for doas, /etc/doas.conf, employs a straightforward syntax with rules in the form of "permit|deny [options] identity [as target] [cmd command]", without support for includes, regular expressions, or complex runas specifications present in sudoers. This design facilitates easier auditing and maintenance due to its linear evaluation (last matching rule applies) and default deny policy, though it offers less flexibility for intricate access controls. In terms of , doas presents a smaller footprint, with its consisting of a single file of approximately 2,500 lines compared to sudo's multi-file exceeding 200,000 lines, resulting in lower overhead for and reduced resource consumption during execution. Security-wise, doas mitigates risks associated with feature bloat by omitting capabilities like session recording or extensive environment manipulation, which have contributed to numerous vulnerabilities in sudo, including over 50 CVEs since 2000 related to and buffer overflows. While doas forgoes some auditing features, its kernel-tied authentication (using process ID checks) and minimal —evidenced by only one known CVE in non-OpenBSD ports—enhance overall configurability and auditability for simpler setups. Migrating from sudoers to doas.conf typically involves manual simplification, as automated tools are unavailable; administrators must translate permissive rules into doas's basic permit/deny structure, often discarding advanced sudo options like timeouts or aliases that have no direct equivalent.

Availability and Ports

Native Implementations

Doas is natively integrated into the base system of several variants, providing a lightweight alternative to for without requiring additional package installation. In , doas has been the default utility since version 5.8, released in October 2015, where it fully replaces sudo in the base installation while sudo remains available as an optional package. This integration ensures doas is immediately usable out-of-the-box, with configuration handled through /etc/doas.conf, emphasizing 's commitment to simplicity and security in core utilities. DragonFly BSD includes support for doas starting from version 5.4, released in December 2018, available via the DPorts package system as security/doas for executing commands with elevated privileges. The utility is configured via /etc/doas.conf, aligning with DragonFly's focus on performance-oriented features while adopting doas for its minimal footprint compared to more feature-heavy alternatives. Official manual pages document its usage, confirming compatibility without reliance on external sources. FreeBSD provides doas via the ports collection under security/doas beginning with earlier versions, including dedicated man pages and example configurations to facilitate adoption. Available since 2016, this allows users to install and leverage doas (e.g., pkg install doas) for system management, reflecting FreeBSD's emphasis on providing versatile, secure tools through its ports system. The utility's presence in the ports collection streamlines administrative tasks across FreeBSD environments. In NetBSD, doas is natively supported through integration with the pkgsrc package collection under security/doas, available in recent releases such as NetBSD 9.0 and later, though not part of the minimal base system install. This setup enables straightforward installation via pkgin install doas or source building from pkgsrc, ensuring compatibility with NetBSD's portable packaging ecosystem while maintaining the utility's original OpenBSD semantics. For illumos-based systems, doas finds native support in distributions like SmartOS, where it is available through the pkgsrc framework with configurations adapted to Solaris-compatible paths such as /etc/doas.conf. This integration allows doas to function within SmartOS's lightweight, RAM-based hypervisor environment, providing privilege escalation for zone management and other administrative operations without conflicting with illumos's SVR4 heritage.

Third-Party Ports and Packages

OpenDoas serves as the primary portable implementation of doas, a community-maintained fork of the original written in portable C to support non-BSD systems. This port enables doas functionality on distributions and other operating systems by adapting the core logic for different authentication backends, such as on . Linux Distributions Several major distributions package OpenDoas or compatible variants, facilitating easy integration as a alternative.
  • In , opendoas is available in the official extra repository, installable via pacman -S opendoas.
  • Debian and its derivatives provide opendoas in the main repository, with the doas package acting as a transitional symlink; installation uses apt install opendoas.
  • includes doas directly in its edge/main repository and has positioned it as the recommended sudo replacement since version 3.16, due to its minimal footprint; install with apk add doas.
  • Gentoo offers it as the app-admin/doas ebuild in the main portage tree, emergeable with emerge app-admin/doas.
  • integrates doas natively, enabled by setting security.doas.enable = true in configuration.nix, with the package available in nixpkgs.
These packages generally handle setuid installation and basic integration automatically. macOS Support On macOS, doas is supported through portable builds of OpenDoas, which leverage the system's BSD-derived authentication for password prompts and . Users can compile from source using Command Line Tools, requiring no additional dependencies beyond the standard build environment; post-build, manual setup (chmod 4755 /usr/local/bin/doas) ensures proper operation. It is also packaged in MacPorts as doas, installable via sudo port install doas, providing seamless integration with macOS security contexts like SIP. While not in the core Homebrew formulae, community taps or manual installation via Homebrew's brew install --HEAD from the repository source are possible for users preferring that manager. Other Systems and Forks Maintained forks extend doas to additional platforms, including FreeBSD, where it is available as a security port (pkg install doas) derived from OpenBSD contributions, offering full compatibility with FreeBSD's authentication. Portable versions have been adapted for niche systems like and through community efforts, focusing on core without full support. Building from across these ports typically requires a C compiler and, on , libpam-dev (e.g., libpam0g-dev on for PAM-enabled builds). Current Adoption (2025) By 2025, third-party doas ports enjoy widespread use in resource-constrained environments, particularly minimal distributions like , where it replaces heavier alternatives for better security and performance. Ongoing maintenance, including security patches addressing issues like CVE-2023-28339, ensures cross-platform reliability, with active development on repositories like Duncaen/OpenDoas.

References

  1. [1]
    doas(1) - OpenBSD manual pages
    DESCRIPTION. The doas utility executes the given command as another user. The command argument is mandatory unless -C , -L , or -s is specified.
  2. [2]
    A port of OpenBSD's doas which runs on FreeBSD, Linux ... - GitHub
    Sep 16, 2025 · The doas utility is a program originally written for OpenBSD which allows a user to run a command as though they were another user.
  3. [3]
    Introduction to doas on OpenBSD | Vultr Docs
    Apr 1, 2025 · OpenBSD 5.8, released in 2015, was the first to include doas . It was created by Ted Unangst after he was dissatisfied with the complexity of ...Missing: history | Show results with:history
  4. [4]
    doas.conf(5) - OpenBSD manual pages
    doas configuration file ; HISTORY. The doas.conf configuration file first appeared in OpenBSD 5.8. ; AUTHORS. Ted Unangst <tedu@openbsd.org>.Missing: introduction | Show results with:introduction
  5. [5]
    OpenBSD doas: Simple sudo Alternative with Secure Access
    May 26, 2025 · The name stands for “dedicated openbsd application subexecutor“. Introduced with OpenBSD 5.8 in 2015, doas was authored by Ted Unangst due ...Missing: history | Show results with:history
  6. [6]
    doas - ArchWiki
    Sep 17, 2025 · Like sudo, doas is used to assume the identity of another user on the system. Installation. Install the opendoas package. Usage. To begin using ...Missing: utility | Show results with:utility
  7. [7]
    Doas - Debian Wiki
    Jul 20, 2023 · Doas is a utility that allows a user account to run a command as another user account. You can think of it as, do it as someone else (hence "doas");Missing: unix | Show results with:unix
  8. [8]
    doas - Gentoo Wiki
    The doas command provides a way to perform commands as another user. It aims to be aa simplified and lightweight replacement for sudo.Missing: unix utility<|control11|><|separator|>
  9. [9]
    Sudo: Its History and How to Abuse It - risk3sixty
    Jan 27, 2020 · Super User Do As or Sudo was first developed in 1980 by Bob Coggeshall and Cliff Spencer. Both Bob and Cliff worked at the Department of ...
  10. [10]
    doas - dedicated openbsd application subexecutor - flak
    Jul 20, 2015 · Three days of the doas. I started working on doas quite some time ago after some personal issues with the default sudo config.Missing: origins | Show results with:origins
  11. [11]
    Innovations - OpenBSD
    Imported April 24, 2015 and first released with OpenBSD 5.8. doas(1): Written by Ted Unangst. Imported July 16, 2015 and first released with OpenBSD 5.8.
  12. [12]
    'CVS: cvs.openbsd.org: src' - MARC
    ### Summary of doas Introduction in OpenBSD
  13. [13]
    src/usr.bin/doas/
    ### Files in src/usr.bin/doas/
  14. [14]
    Sudo and its alternatives - LWN.net
    Feb 21, 2024 · It was developed by Ted Unangst, who had " personal issues " with the configuration of sudo. He wrote a blog post in July 2015 explaining his ...
  15. [15]
    OpenBSD FAQ: Building the System from Source
    Snapshots of the -current branch are made available between formal releases of OpenBSD. These are builds of whatever code is in the tree at the time. A recent ...
  16. [16]
  17. [17]
    doas.conf(5) - OpenBSD manual pages
    ### Summary of `doas.conf` Configuration Simplicity and Authentication
  18. [18]
  19. [19]
    doas mastery - flak
    Sep 5, 2016 · We're nearing the end of our tour of the doas.conf syntax. doas can also be restricted so that rules only apply for certain commands, or even ...
  20. [20]
  21. [21]
    Vulnerability in sudo is a great example of openbsd philosophy
    Feb 3, 2021 · sudo is an astoundingly large 223,957 lines of code* spanning 558 files, while doas is only 77 403 lines of code in a single file! Like many ...Some one give me a use case for OpenBSD - RedditWhy are people sold on Doas? : r/freebsd - RedditMore results from www.reddit.com
  22. [22]
    Sudo Project Sudo security vulnerabilities, CVEs, versions and CVE ...
    This page lists vulnerability statistics for all versions of Sudo Project » Sudo. Vulnerability statistics provide a quick overview for security vulnerabilities ...Missing: count | Show results with:count
  23. [23]
    CVE-2019-15901 Detail - NVD
    Oct 18, 2019 · An issue was discovered in slicer69 doas before 6.2 on certain platforms other than OpenBSD. A setusercontext(3) call with flags to change the ...
  24. [24]
    doas - sudo alternative | The FreeBSD Forums
    Jan 19, 2019 · doas is a sudo alternative ported from openbsd. install doas Bash: # pkg install doas create the doas config file Bash: # vi /usr/local/etc/doas.confdoas tips - sudo alternative | The FreeBSD Forumssudo or doas | The FreeBSD ForumsMore results from forums.freebsd.orgMissing: unix utility
  25. [25]
    A simple guide for configuring sudo and doas - DEV Community
    Dec 24, 2023 · Doas was created by Ted Unangst for OpenBSD,as a simpler and safer alternative to sudo . doas is not configured by default on most distros,but ...
  26. [26]
    OpenBSD 5.8
    Oct 18, 2015 · This is a partial list of new features and systems included in OpenBSD 5.8. For a comprehensive list, see the changelog leading to 5.8.
  27. [27]
    release54 - DragonFlyBSD
    DragonFly version 5.4 brings a new system compiler in GCC 8, improved NUMA support, a large number of network and virtual machine driver updates ...Missing: doas | Show results with:doas
  28. [28]
    FreeBSD 13.0-RELEASE Release Notes
    Jan 9, 2023 · This document contains the release notes for FreeBSD 13.0-RELEASE. It describes recently added, changed, or deleted features of FreeBSD.
  29. [29]
    The pkgsrc guide
    Jul 24, 2025 · pkgsrc is a centralized package management system for Unix-like operating systems. This guide provides information for users and developers of pkgsrc.Chapter 5. Using pkgsrc · II. The pkgsrc developer's guide · Chapter 2. Getting helpMissing: doas integration
  30. [30]
    SmartOS Documentation
    SmartOS is a Type 1 Hypervisor based on illumos, a live OS that runs from memory, supporting both OS and hardware virtualization.Hardware Requirements · Illumos and SmartOS Basics · Download SmartOS · ZFSMissing: doas | Show results with:doas
  31. [31]
    Duncaen/OpenDoas: A portable fork of the OpenBSD `doas` command
    If you want to use OpenDoas on your system and there is no package that ships with a working PAM configuration file, then you have to write and test it yourself ...
  32. [32]
    opendoas 6.8.2-3 (x86_64) - Arch Linux
    Architecture: x86_64. Repository: Extra. Description: Run commands as super user or another user. Upstream URL: https://github.com/Duncaen/OpenDoas.<|control11|><|separator|>
  33. [33]
    Debian -- Details of package opendoas in trixie
    OpenDoas: a portable version of OpenBSD's doas command doas is a minimal replacement for the venerable sudo. It was initially written by Ted Unangst of the ...
  34. [34]
    Alpine Linux 3.16.0 Released
    May 23, 2022 · Suggested replacement is doas and doas-sudo-shim. Upgrade notes. As always, make sure to use apk upgrade --available when switching between ...
  35. [35]
    doas - Alpine Linux packages
    Package, doas. Version, 6.8.2-r8. Description, OpenBSD's temporary privilege escalation tool. Project, https://github.com/Duncaen/OpenDoas. License, ISC.
  36. [36]
    app-admin/doas - Gentoo Packages
    app-admin/doas Run commands as super/another user (alt sudo) (unofficial port from OpenBSD) https://github.com/Duncaen/OpenDoas
  37. [37]
    Packages - doas - NixOS Search
    Showing results 1-2 of 2 packages. Data from nixpkgs ca534a76 . doas. Executes the given command as another user. Name: doas; Version: 6.8.2 ...
  38. [38]
    Install doas on macOS with MacPorts
    To install doas, run the following command in macOS terminal (Applications->Utilities->Terminal). sudo port install doas ; To see what files were installed by ...
  39. [39]
    doas - Simple sudo alternative to run commands as another user
    Jun 24, 2016 · This is the FreeBSD port of the OpenBSD "doas" command. The doas program allows a regular user to run commands as another user (usually root).
  40. [40]
    opendoas - Debian Package Tracker
    CVE-2023-28339: OpenDoas through 6.8.2, when TIOCSTI is available, allows privilege escalation because of sharing a terminal with the original session. NOTE: ...