How To Create And Configure Sudo User On Arch Linux
Step 1) Install sudo package
Right off the bat, we need to install the sudo utility. Unlike other Linux distributions, this is not included by default in the base install. To install this, execute the following command as root:
# pacman -S sudo
Step 2) Create a regular user
Next, we need to create a regular user. We will later add this user to the sudoers group to enable them to carry out administrative tasks.
To create a sudo user, use the useradd command as shown:
# useradd -m -G wheel -s /bin/bash username
Let’s break down the command:
The -m option creates a home directory for the user /home/user.
The -G option adds the user to an additional group. In this case, the user is being added to the wheel group.
The -s option specifies the default login shell. In this case, we are assigning bash shell denoted by /bin/bash.
So, let’s assume you want to add a regular user called techuser. To accomplish this, run the command as follows:
# useradd -m -G wheel -s /bin/bash techuser
Step 3) Configure the regular user as sudo user
What we have so far done is to create a regular login user. The user does not yet have the capability of running elevated commands. We need to edit the sudoers file located at /etc/sudoers
The wheel group is a special type of group in Linux systems that controls who has access to sudo commands.
To confirm that the wheel group is enabled, execute the command:
# visudo
Or
# vi /etc/ sudoers
This ushers you to the sudoers file which is rendered on a vim editor. The sudoers file defines access rights and can be edited to grant or deny certain privileges to regular users.
Once you have opened the sudoers file, scroll and locate the following entry. In the basic arch linux installation it would be commented. Uncomment it and save the file to enable the wheel group.
%wheel ALL=(ALL) ALL
As we have already a regular user, let’s assign password as shown using the passwd command.
# passwd techuser
When prompted, provide the new user’s password and confirm it.
Alternate way to configure regular user as sudo user, add following user’s entry in the sudoers file as shown below,
# vim /etc/sudoers
Under the User privilege specification section, add the following line.
techuser ALL=(ALL) ALL
Local-User-Sudoer-File-Arch-Linux
Save and exit the sudoers file
Step 3) Testing the sudo user
Lastly, we are going to confirm if the user can perform root tasks. First, switch over to the new user.
$ 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.