How to Create a Sudo User on CentOS

How to Create a Sudo User on CentOS


The sudo command is designed to allow users to run applications with another user’s security rights, by default the root user.

Log in to your CentOS system as the root user.

$ ssh root@server_ip_address

 Create a normal user account called fosnix using the useraad command, the -m option means to create the user’s home directory if it doesn’t exist, -s defines the new user’s login shell program (which is /bin/bash in this case) and -c defines a comment indicating that this is an administrative user account.

$ useradd -m -s /bin/bash -c "Administrator" fosnix

Replace fosnix with the user name that you wish to create and Set a password for the newly created user account using the passwd command

On all Linux distributions that belongs to the RHEL family, only users in the wheel system group can run a command with sudo. So, next, add the new user fosnix to the wheel group using the usermod command. Here, the -a flag means to append user to a supplementary group and -G specifies the group. 

$ usermod -aG wheel fosnix
$ cat /etc/group | grep -i wheel

Now, you will login with your Username and Password

$ passwd fosnix

As the new user, verify that you can use sudo by prepending “sudo” to the command that you want to run with superuser privileges.

$ sudo ls -la /root


No responses yet

Leave a Reply

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

Latest Comments

No comments to show.