Hasan MN


Adding a Non-Root User With `sudo` Privilege in CentOS Linux

Hasan MN's photo
Hasan MN
·Jan 19, 2022·

1 min read

In one of my previous post , I wrote about how to add a user with sudo privilege in Ubuntu linux. In this post, let me write a similar one but for CentOS Linux.

First, let's add a user, which can be done using

adduser username

For example, if we want to add johndoe user, then you have to run adduser johndoe.

Next, we can set the password of the created user using

passwd username

Running that command, you will be asked to enter a new password, with it's confirmation.

Finally, we have to add the created user to the wheel group. This can be done uing usermod command as follows.

usermod -aG wheel username

Members of the wheel group on CentOS have sudo privileges.

Now, if you want to switch to the newly created user by running

su - username

Because the created user has sudo privilege, we can now run any command prefixed by sudo, e.g., sudo yum install vim.


Share this