How to Create a Sudo User on Fedora 37/36/35

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 additional sudo users or make the default user have sudo rights.

In the following tutorial, you will learn how to create a sudo user and some handy hints and methods on a Fedora 37/36/35 Linux desktop or headless server using the command line terminal.

Change to Root Account on Fedora Linux

To create new sudo users, you will need to 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, then enter a new root password once verified.

Example output:


change root password if forgotten on Fedora Linux

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:

login to root account on Fedora Linux

As mentioned above, you now have root@ instead of your @username.

Create a User Account on Fedora Linux

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

sudo adduser <example username>

Example:


sudo 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:

example creating new user on Fedora Linux

Add New User To Sudoers Group on Fedora Linux

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:

sudo usermod -aG wheel <example username>

Example using our name we created:

sudo 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:

id command check on new sudo user on Fedora Linux

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 on Fedora Linux

Now that you have successfully added the user you wanted sudo access, 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 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:

switch to new root account username on Fedora Linux

Congratulations, you have added a new username to the sudoers group.



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

Leave a Comment