How to add a user in sudoers file redhat Or How to configure a user tohave sudo access

How to add a user in sudoers file redhat Or How to configure a user tohave sudo access

Sodo command offers administratoors a mechanism to provide users trusted users administrative rights withou the need to share the root password. Once a user is the part of sudo (Authenticated) they will get all the previlages of a root user.

1) Add a new user

useradd steve

# passwd steve
Changing password for user steve
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

Edit the /etc/sudoers file using the command visudo

#visudo

Find the lines in the file that grant sudo access to users in the group wheel when enabled.

## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

Remove the comment character (#) at the start of the second line. This enables the configuration option.
Save your changes and exit the editor.
Add the user you created to the wheel group using the usermod command.

# usermod -aG wheel USERNAME

Test that the updated configuration allows the user you created to run commands using sudo.

Use the su to switch to the new user account that you created.

# su steve –

Use the groups to verify that the user is in the wheel group.

$ groups
steve wheel

Use the sudo command to run the whoami command. As this is the first time you have run a command using sudo from this user account the banner message will be displayed. You will be also be prompted to enter the password for the user account.

$ sudo whoami
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for steve:
root

The last line of the output is the user name returned by the whoami command. If sudo is configured correctly this value will be root.

Leave a Reply

Your email address will not be published. Required fields are marked *

*