On a lot of Linux systems, you can perform tasks as root by running commands with sudo. The OpenBSD project has developed a minimalistic alternative, doas.

So, how do you use doas to execute Linux commands as another user, and will it ever replace sudo?

What Is doas?

doas is a utility that allows standard users to perform tasks as root, the same way sudo does. It's been developed by the OpenBSD project as a minimalistic alternative to sudo, and as a result, the program is much smaller than sudo.

While it's developed as a part of OpenBSD, a portable version is available that works with other Unix-like systems, including Linux.

How to Install doas

doas is available on most official distro repositories and you can easily install it using your distribution's package manager. To install doas on Debian-based distros like Ubuntu:

        sudo apt install doas
    

Note that the package is only present in the Ubuntu 21.04 repository and not in the 20.04 LTS release.

To install it on Arch, just use pacman:

        sudo pacman -S opendoas
    

On Fedora and CentOS, use DNF to install doas:

        sudo dnf install opendoas
    

Configuring doas

doas takes some more setup than sudo because most distros still don't include it by default, but the configuration is much easier to understand than sudo. All you have to do is edit the /etc/doas.conf file as root.

Here is an example of doas that mimics the behavior of sudo, and lets you run any command as root. Using doas, you also get a grace period where you don't have to enter your password for several minutes after running successive doas commands.

        permit persist username as root
    

The username in the aforementioned command is the user you want to enable. Many systems have users in a certain group such as "admin" or "wheel" that can use sudo. You can also duplicate this with doas by preceding group names by a colon.

        permit persist :wheel as root
    

You can also specify Linux commands with doas. Suppose you only want a particular user to be able to run APT to update the system. The cmd option lets you specify a list of individual commands and nopass will let you run root commands without a password.

        permit nopass user cmd apt apt-get as root
    

Using Doas

You use doas at the command line just as you would run sudo:

        doas apt update
    

Related: How to Change Between Users on Linux

What About sudo?

Despite the arrival of doas, sudo will be around for a while. Although sudo has a convoluted configuration file, it offers a lot of fine-grained control. Plus, doas is not yet available in all distro repositories. You'll likely have to use sudo until either more repositories add it or distros start replacing sudo with doas as the default administrative program.

Apart from doas and sudo, there are several other programs that you can install to run commands as another user. Many Linux distros including Arch Linux ship with su as the default utility to switch between users.