Sudo allows us to provide superuser privileges to a normal user with restrictions. It allows users to run programs with the privileges of the superuser. You can configure sudo to give root privileges to specific commands only. Anyone working with the sudo privileges always remember a famous quote:
With great power comes great responsibility
Advertisement
This tutorial provides you the step by step instructions to create a new user with sudo privileges on CentOS and RHEL systems. Also, help you to allow sudo access to the existing accounts.
Steps to Create a Sudo User on CentOS
- Access the Terminal : Log in to your CentOS server via a terminal window. If you’re using a remote server, connect to it using SSH.
- Create a New User Account: Use the useradd command to create a new user. Replace newuser with the desired username.
useradd newuser
You will not receive any feedback if the command was successful.
- Set a Password for the New User: Assign a password to the new user account with the passwd command. This will prompt you to enter and confirm the password.
passwd newuser
Ensure the password is strong and secure.
- Add the New User to the Wheel Group: In CentOS, members of the wheel group are granted sudo privileges. Add your new user to this group with the following command:
usermod -aG wheel newuser
The -aG option adds the user to the supplementary group (wheel in this case).
- Verify Sudo Access: Switch to the new user account:
su - newuser
You can test sudo access by running a command that requires administrative privileges. For example:
sudo ls -la /root
The first time you run a command with sudo, you will be asked to enter the password for the newuser account.
- Customize Sudo Privileges (Optional): If necessary, you can customize the sudo privileges by editing the sudoers file. Do this with caution:
sudo visudo
It’s important to be very careful when making changes to the sudoers file, as incorrect configurations can lead to security risks or lock you out from administrative access.
Conclusion
By completing these steps, you have successfully created a sudo user on your CentOS system. This practice allows for more controlled and secure execution of administrative commands, minimizing the risks associated with operating as the root user. Always remember to use sudo privileges responsibly, ensuring you understand the implications of the commands you are executing with elevated rights. This approach is fundamental for maintaining the security and stability of your CentOS system.