Sudo is a powerful command line tool that allows users to run programs with administrative privileges. To use sudo, a user must first be added to the sudoers file. When installing Fedora, the user account created during the initial setup should have access to sudo rights. However, there may be a need to add sudo users or make the default user have sudo rights. The following tutorial will teach you how to create a sudo user and some handy hints and methods on a Fedora Linux desktop or headless server using the command line terminal.
Table of Contents
Change to Root Account
To create new sudo users, you must switch to root using the su command. By default, this was not set during the installation. Do not panic; you can reset the password as follows.
sudo passwd root
Next, you will be prompted to enter your sudo account’s password and a new root password once verified.
Example output:
Now that your root password has been set switch to root using the following command su:
su
You will be prompted for the root password. Once entered, you will see the username has changed to root.
Example:
As mentioned above, you now have root@ instead of your @username.
Create a User Account
First, create the user account <example username>, replacing the sample with the user name you want to add.
adduser <example username>
Example:
adduser josh
Next, you need to set the password for the added user name.
In the tutorial example, the username is “josh.”
sudo passwd josh
Example:
Add New User To Sudoers 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 typing the following command:
usermod -aG wheel <example username>
Example using our name we created:
usermod -aG wheel josh
Use the following id command to check if the username is in the sudo “wheel” group.
id <username>
Example using our name we created:
id josh
Example output:
An alternative is to use the gpasswd command as follows:
gpasswd -a <example username> wheel
Example using our name we created:
gpasswd -a josh wheel
Example output:
Adding user josh to group wheel
Confirm New Sudo User
Now that you have successfully added the user you wanted sudo access, it is time to test the account. This can be done again using the su command but by adding the username and the command.
Login to sudo user as follows.
su <example username>
Example using our name we created:
su josh
Now, confirm the username with the sudo command along with whoami.
sudo whoami
You will then be prompted to type in the sudo username you are using and its password.
Once entered and confirmed, you will see the following output:
Congratulations, you have added a new username to the sudoers group.
Conclusion
This tutorial demonstrated adding a new user on Fedora Linux using the command line terminal. Also, it showed how to give sudo rights and verify that it worked on the newly added user. These are two essential skills for anyone working with Linux. With these skills, you can easily add new users and give them sudo privileges when needed.