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:
Enter the root user password.
2. Run the command below to add a new user:
3. Set a new password for this user using the command below:
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:
In the file, look for the line that says:
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.
5. Now to grant any user sudo privilege, add it to the wheel group using the command below:
For instance, to grant a user “umara” sudo privileges, we will need to add it to the “wheel” group using the command below:
6. To verify if the user has been added to the “wheel” group, run the command below:
You should see the “wheel” group in the output of the above command.
7. Now to verify if the user has got the sudo access, switch to that user using the command below:
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.
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.