Want a better replacement for the standard sudo command? You're lucky. Learn how to install and set up the doas utility on Linux.
On many Linux systems, you can perform tasks as root by running commands with sudo. The OpenBSD project has developed a minimalist alternative, doas.
So how do you use Doas to run Linux commands as a different user and will it ever replace sudo?
What is doas?
doas is a utility that allows standard users to perform tasks as root, just like sudo. It was developed by the OpenBSD project as a minimalist alternative to sudo and is therefore much smaller than sudo.
Although it was developed as part of OpenBSD, a portable version is available that works with other Unix-like systems, including Linux.
How to install doas
doas is available in most official distribution repositories and you can easily install it using your distribution's package manager. To install Doas on Debian-based distributions like Ubuntu:
sudo apt install doas
Note that the package is only in the Ubuntu 21.04 repository and not the 20.04 LTS version.
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
doas takes a little more setup than sudo as most distributions still don't come with it by default, but the configuration is much easier to understand than sudo. All you have to do is edit that /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 also gives you a grace period in which you don't have to enter your password for several minutes after running successive doas commands.
allow username to be kept as root
the Username in the above command is the user you want to enable. Many systems have users in a specific group like "admin" or "wheel" who can use sudo. You can also duplicate this with doas by prefixing group names with a colon.
allow persist: wheel as root
You can also specify Linux commands with doas. Suppose you want only a specific user to be able to run APT to update the system. the cmd Option allows you to specify a list of individual commands and no passport lets you run root commands without a password.
allow nopass user cmd apt apt-get as root
You use doas on the command line just like you would run sudo:
doas apt update
What about sudo?
Despite the arrival of Doas, sudo will be around for a while. Although sudo has a kinky configuration file, it offers a lot of fine-grained control. In addition, doas is not yet available in all distribution repositories. You will likely have to use sudo until more repositories either add it or the distros start replacing sudo with doas as the default management program.
Aside from doas and sudo, there are several other programs you can install to run commands as a different user. Many Linux distributions, including Arch Linux, come with su as the default utility to switch between users.
Sudo vs. su: which command should you use?
On Linux there are two commands to get superuser access: su and sudo. Which one you should use depends on the task at hand.
About the author
(61 published articles)
David is a freelance writer living in the Pacific Northwest but originally from the Bay Area. He has been passionate about technology since childhood. David's interests include reading, watching quality TV shows and movies, retro games, and collecting records.
By David Delony
Subscribe to our newsletter
Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive offers!
Click here to subscribe