Linux Commands

How Do I Run as Sudo Root in Fedora

A root user has all the administrative access in a Linux OS. Some of the root privileges include removing a file, adding/removing a user account, installing/removing an application, changing file permissions, etc. A standard user does not have this kind of privileges. However, an administrator can grant a standard user sudo privileges to run administrative commands. This way a standard user (non-root user) can run administrative commands without logging in as a root user. The commands then run as if that user is an administrator.

This post describes how to run commands as sudo root in Fedora. It will cover the step-by-step process on how to add a user, set a password for it, and then assign it sudo privileges. In the end, we will verify if the user has been granted the sudo privileges and can run the commands as sudo.

1. Login as a root user using the command below:

$ su -

Enter the root user password.

2. Run the command below to add a new user:

$ adduser <username>

3. Set a new password for this user using the command below:

$ passwd <username>

4. In Linux, the /etc/sudoers file defines which users are allowed to use the sudo command and which commands they are allowed to run. You can edit this file using the command below:

$ visudo

In the file, look for the line that says:

%wheel ALL=(ALL) ALL

This line grant all members of the group wheel to run all commands as sudo. Make sure the above line is not commented (does not have a # symbol at its beginning). If the line is commented, remove the # symbol and then save and exit the editor.

/etc/sudoers file

5. Now to grant any user sudo privilege, add it to the wheel group using the command below:

$ usermod -aG wheel <username>

For instance, to grant a user “umara” sudo privileges, we will need to add it to the “wheel” group using the command below:

$ usermod -aG wheel umara

adding user to "wheel" group

6. To verify if the user has been added to the “wheel” group, run the command below:

$ id <username>

You should see the “wheel” group in the output of the above command.

id <username>

7. Now to verify if the user has got the sudo access, switch to that user using the command below:

$ su - <username>

After running this command, you will see the prompt has been changed to the new user. Now try running any command as sudo like sudo ls, sudo dnf update, etc. It will ask for the sudo password. Enter the password for the user account, not the root account. Now, the command will run and you will see the output.

verifying sudo access

If you receive a message like “<username> is not in the sudoers file. This incident will be reported”, it means the procedure has not been done correctly and the user has no sudo privileges. Make sure you are logged in as root and have followed all the steps correctly.

The sudo command allows users to run administrative commands without needing the root password. In this post, we shared how you can run commands as sudo root in Fedora. Remember, you can also restrict which commands a user can run as root. Therefore, if some users do not require full root access, they can be provided access solely to the tasks they need to accomplish.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.