Create sudo user in CentOS

How to create a user in CentOS and give sudo access To create a user in CentOS follow these steps

  1. You must be logged in as root to add a new user

  2. Issue the useradd command to create a locked account

    useradd <username>
    

  3. Issue the passwd command to set the password of the newly created user

    passwd <username>
    

This will you prompt you to enter the password of the newly created user

  1. To give the user sudo access you need to add the user to wheel group

To do this issue the command : visudo

To be able to add a user to the wheel group you must uncomment the line ie

#%wheel   ALL=(ALL)   ALL
to
%wheel   ALL=(ALL)   ALL

  1. Adding the newly created user to wheel group

    usermod -G wheel  <username>
    

  2. Finished - Your user now has sudo access !! enjoy !!


Last update: November 7, 2023
Back to top