Centos Create User With Root Privileges

admin14 April 2024Last Update :

Understanding Root Privileges in CentOS

In the world of Linux, including CentOS, root privileges are akin to having administrative access. This level of access allows a user to perform critical system tasks that regular users cannot, such as installing software, changing system configurations, and managing other user accounts. Before we delve into creating a user with root privileges, it’s essential to understand the implications of granting such access.

The Power of the Root User

The root user is the default superuser in the Linux operating system. It has unrestricted access to all commands and files. With great power comes great responsibility; hence, it’s crucial to limit the use of the root account to reduce the risk of accidental system damage or security breaches.

Sudo: A Safer Alternative to Direct Root Access

Instead of logging in directly as root, CentOS and other Linux distributions recommend using the sudo command. Sudo stands for “superuser do” and allows permitted users to run specific commands as the root user without needing the root password.

Creating a New User in CentOS

Before granting root privileges, you must first create a new user. In CentOS, this can be done using the useradd command followed by the username.

useradd [username]

Setting a Password for the New User

After creating a new user, set a password using the passwd command:

passwd [username]

You will be prompted to enter and confirm the new password for the user.

Granting Root Privileges to a User

To grant root privileges to a user, you need to add them to the ‘wheel’ group, which is pre-configured in CentOS to allow its members to execute any command using sudo.

Adding a User to the Wheel Group

Use the usermod command to add your user to the wheel group:

usermod -aG wheel [username]

The -aG option appends the user to the specified group without removing them from other groups.

Configuring Sudo Privileges

CentOS uses the /etc/sudoers file to define permissions for sudo. It’s recommended to edit this file using the visudo command, which locks the file against multiple simultaneous edits and performs a syntax check on save.


Within the /etc/sudoers file, locate the line that includes %wheel and ensure it’s uncommented:

%wheel ALL=(ALL) ALL

This line means that all members of the wheel group have sudo privileges.

Testing New User Sudo Access

Switch to the new user account and attempt to run a command with sudo to test their new privileges:

su - [username]
sudo [command]

If configured correctly, after entering the user’s password, the command should execute with root privileges.

Best Practices for Managing Users with Root Privileges

When managing users with root privileges, follow these best practices to maintain system security and integrity:

  • Limit Sudo Access: Only grant sudo privileges to trusted users who require them for their work.
  • Use Strong Passwords: Ensure that all users with sudo access have strong, unique passwords.
  • Regular Audits: Periodically review the list of sudoers and remove any users who no longer need access.
  • Monitor Sudo Usage: Keep an eye on the usage of sudo through log files located at /var/log/secure or /var/log/auth.log.

FAQ Section

What is the difference between adding a user to the wheel group and editing the sudoers file?

Adding a user to the wheel group is a quick way to grant sudo privileges based on a pre-defined policy in the sudoers file. Editing the sudoers file allows for more granular control over what commands a user can execute with sudo.

Is it safe to give a user root privileges?

It can be safe if managed properly, but it also increases the risk of accidental or malicious changes to the system. Always follow best practices and limit root access to users who absolutely need it.

How can I revoke a user’s sudo privileges?

To revoke sudo privileges, remove the user from the wheel group using the gpasswd command or edit the sudoers file to remove their specific entry.

gpasswd -d [username] wheel

Can I customize the commands a user can run with sudo?

Yes, you can specify particular commands in the sudoers file that a user is allowed to run. This is done by editing the sudoers file and adding specific entries for the user.

How do I view all users with sudo privileges on my CentOS system?

You can see all users with sudo privileges by checking the wheel group members and reviewing the sudoers file. Use the getent group wheel command to list wheel group members and inspect the sudoers file with visudo or by viewing it directly.

getent group wheel


Leave a Comment

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

Comments Rules :

Breaking News