How to Create/Add a Sudo User on Arch Linux

Depending on the options you set when installing Arch Linux, you may have just installed with the root account active, or only one user with sudo permission may require adding more users with this permission. This can be done quickly and easily and is often preferred over root access.

In the following tutorial, you will learn to add a user to the sudoers group on Arch Linux using the command line terminal.

Install Sudo Package

First, install the sudo package if you are in the root account with no sudoers created yet. For users that have sudo installed, skip this part.

pacman -Sy sudo

Changing to the root account (su)

When creating new sudo users, you will need to switch to root using the su command. This does not apply to users in the root account, but for those in a sudo account already and who have forgotten the root password you set, use the following command to reset the password.

sudo passwd root

Next, you will be prompted to enter your sudo account’s password, then enter a new root password once verified.

Now that your root password has been set switch to root using the following command su root.

su root

When changing to any user account with root access, you will be prompted for the passwordOnce entered, you will see the username has changed to root.

Create a User Account

The first step is learning how to add a new user account. Ideally, you can grant permission to an existing account, but you will learn to add a user from scratch for the tutorial.

First, create the user account <example username>, replacing the example with the user name you want to add.

useradd -m -G wheel -s /bin/bash <username>

Example using my username creation:

useradd -m -G wheel -s /bin/bash josh

The useradd command flags mean the following for those curious about what they are.

  • -m: Creates a home directory for the user /home/user.
  • -G: Adds the user to a different group. In this case, the user is being added to the wheel group.
  • -s: Specifies the default login shell. In this case, assign a bash shell denoted by /bin/bash.

Next, set the password for the user account using the following command.

passwd <username>

Example with my username creation:

passwd josh

Add User to Sudo (Wheel) Group

In the next part of the tutorial, now that you have learned how to add a user, you can give the new user that you named or an existing username sudoers access by modifying the /etc/sudoers file using your favorite text editor.

The tutorial will use nano, most Arch Linux users would use something like Vim or VI, but for newcomers, nano would be easiest until you get more comfortable.

First, install nano.

pacman -Sy nano

Next, open the configuration file.

sudo nano /etc/sudoers

Under the “User privilege specification” section, add the following line.

username ALL=(ALL:ALL) ALL

Remember to change your username with the one you created for this purpose.


How to Create/Add a Sudo User on Arch Linux

Alternatively, you can uncomment the entire %wheel group, so anyone automatically added will be given sudo privilege, this user choice.

Example line to uncomment:

 %wheel   ALL=(ALL)   ALL


How to Create/Add a Sudo User on Arch Linux

It is good to check if the username was successfully added to the sudoers group. To do this, run the id command:

id <username>

Example using our name we created:

id josh

Example output:

How to Create/Add a Sudo User on Arch Linux

An alternative is to use the gpasswd command. Ensure you have uncommented the wheel group, as shown in the configuration file examples in the tutorial.

gpasswd -a <example username> wheel

Example using our name we created:

gpasswd -a josh wheel

Example output:

How to Create/Add a Sudo User on Arch Linux

Confirm & Test New Sudo User

Now that you have successfully added the user you wanted to have sudo access to, it is time to test the account. This can be done again by using the su command but by adding the username along with the command.

Login to sudo user as follows:

su <example username>

Example using our name we created:

su josh

Now, confirm the username has root access by using the command whoami.

sudo whoami

Example output:

How to Create/Add a Sudo User on Arch Linux

Once you have confirmed the root status above, run a quick update command with sudo on the account to ensure it is working correctly.

sudo pacman -Syu

Example output:

How to Create/Add a Sudo User on Arch Linux

Congratulations, you have sudo access to the username you have created.

Comments and Conclusion

The tutorial taught you how to create and add a user on Arch Linux and configure sudo permissions. Overall, this tutorial should work for all supported versions and is recommended only to give permissions to trusted users as they will have access to sensitive files with the permit provided by sudo.

Not what you were looking for? Try searching for additional tutorials.

Leave a Comment