How to add users to sudoers or sudo groups on Arch Linux

Sudo Allows one user to execute commands or programs with security privileges of another user (superuser by default). The superuser on Linux is called ‘root’.

It is one of the best security practices to use non-root users to perform server administration.

In this short article we will create a user and add to a sudo group in Arch Linux.


Add to sudo group

As already mentioned sudo With the command you can run programs with superuser rights. In Arch Linux, sudo is not part of the base installation. So if you don’t have sudo installed, install it using the command below.

# pacman --sync sudo

Also install the vi editor.

# pacman --sync vi

Now add a user to his home directory with the –create-home. to create

# useradd --create-home john

Assign password,

# passwd john

Add users in Arch Linux
Add users in Arch Linux

Wheel group is the sudo group in Arch Linux. At this point, add the newly created user ‘john’ to the bike group using the usermod command.

# usermod --aG wheel john

Now edit the sudoers file so that the bike group is activated. To do this, open the sudoer file and uncomment the line% wheel ALL = (ALL) ALL

# visudo

The end result should look like this:


Uncomment the sudoers file in Arch Linux
Uncomment the sudoers file in Arch Linux

Save and exit visudo. Press Esc, then: wq and press Enter

Now test your configuration by going to user john and using the id command to view the group. You should see root when you type the sudo whoami command.

# su - john

$ id

$ sudo whoami

Check the sudo user in Arch Linux
Check the sudo user in Arch Linux

Remove users from the Sudoers group

If you want to remove a user from sudo (wheel group) use the gpasswd tool as described below. In our case the user is John,

# gpasswd -d john wheel

diploma

We showed you how to add users to the sudo group on Arch Linux. We recommend that you use sudo users instead of the root user when performing administrative tasks. This also helps in giving the right person the appropriate permission. Thank you for coming here.