You will able to execute root privilege commands only if your user account has sudo access. The sudo access can have permissions to execute some specific sort of commands or can have full permissions similar to root account in the system. In this following blog, you will learn how to add a user account into sudo group in redhat linux.
Prerequisites:
1. Sudo access user account.
Things to Mind before adding a user into sudo group :
- Ensure you are in the correct host machine using hostname command.
- You can either add the user into group which as sudo access in the system or can add the user account alone in the /etc/sudoers file.
- While before adding the user into sudo group, ensure the user has to be only in sudo group and not in other group or user has to appended with already existing groups and not removing the user from other groups to gain sudo access. For Example. Developers – group.
Here are the steps to add a user account into sudo group in linux system.
1. Execute the below command to add the user into sudo group alone.
sudo usermod –a wheel <username>
-a – to add the user into sudo group.
As <wheel> group has sudo access, adding the user into that group will have sudo access. Verify the access by using below commands.
id <username>
sudo grep –i <username> /etc/passwd
2. If the user wants sudo access without removing the user from primary group, use below command to add the user into user’s secondary groups.
sudo useradd –aG wheel <username>
-G – To add the user into user’s secondary(supplementary) group with sudo access.
Alternate method:
Edit the /etc/sudoers file with caution using any of the text editors like vi, vim or nano and add the user in the last line of the file.
1. Execute this command on the shell.
sudo vim /etc/sudoers
or
sudo visudo
2. Press “i” on the keyboard to go into insert mode.
3. Add a line <username> ALL=(ALL) ALL on last line of the file or below the line “Allow the root to run any commands anywhere”
4. Press Esc, give :wq! to save the file.
5. Now verify the sudo access of the user using sudo su – <username>
How do you feel about this post? Drop your comments below..