sudo (super user do) is an ordinary user who is granted root or advanced privileges and can therefore perform advanced tasks similar to the root user. These include editing configuration files, installing and removing packages, starting and stopping services, and more.
Instead of running administrative level commands as root, it is recommended to configure or create a sudo user on any Linux server you plan to manage. Executing commands as root is risky, one command can accidentally crash your system. To avoid this, it is strongly recommended to run elevated operations as a sudo user.
In this guide, we will focus on how to create and configure a sudo user on Arch Linux.
1) Install the sudo package
Unlike other Linux distributions, Arch Linux does not have a sudo command by default, execute the following command as root
# pacman -S sudo
2) Create a normal user
Create a normal user and later add this user to the sudoers group to enable them to perform administrative tasks.
Use the useradd command to create a sudo user, the syntax is as follows:
# useradd -m -G wheel -s /bin/bash username
Parameter Description:
- The -m option creates a home directory
- The -G option adds the user to another group
- The -s option specifies the shell to use for default login
Suppose you want to add a common user named techuser, run the following command:
# useradd -m -G wheel -s /bin/bash techuser
Note: The wheel group is a special type of group used to control who has access to the sudo command.
3) Configure ordinary users as sudo users
So far we have created a regular login user, which does not yet have the ability to run elevated commands, we need to edit the /etc/sudoers file.
Note: The /etc/sudoers file defines access permissions and can be edited to grant or deny certain privileges to normal users.
# visudo
Or
# vi /etc/ sudoers
With the sudoers file open, scroll to the relevant part of the wheel, uncomment it and save the file.
%wheel ALL=(ALL) ALL
Use the passwd command to set a password for a user
# passwd techuser
Another way to configure a normal user as a sudo user is to add the following user entry in the sudoers file
techuser ALL=(ALL) ALL
Save and exit the sudoers file
3) Test sudo user
First, switch to a new user
$ su - techuser
Enter the user password and press enter
Let's try to update Arch Linux to see
$ sudo pacman -Syu
You will be provided with a disclaimer informing you of the salient things to keep in mind when invoking sudo and later, you will be prompted for the password.
You will be given a disclaimer informing you of important things to remember when invoking sudo, and you will be prompted for your password later.