I followed following steps to add a new user and later gave it sudo privilege.

  1. Use adduser command to add a new user or if you already have a user to give sudo access skip adduser. Its syntax is ‘adduser usernmae’
    1. [root@centos-10d ~]# adduser devlab
  2. Set a password for new user using passwd command
    1. [root@centos-10d ~]# passwd devlab
    2. choose suitable password based and accessibility to the host.
  3. Add the User to the wheel Group using usermod command. Reason to add in wheel group we can see in sudoers file. Please check sudoers file using visudo command and look for wheel, we can see line – “Allows people in group wheel to run all commands
    1. [root@centos-10d ~]# usermod -aG wheel devlab
  4. Verify the sudo access by switching to the sudo user and user sudo -i
    1. [root@centos-10d ~]# su – devlab
    2. [devlab@centos-10d ~]$ sudo -i
  5. Switch again to devlab and user@host will change to new user and verify any root accessible dir.
    1. [root@centos-10d ~]# su devlab
    2. sudo ls -la /root

[root@centos-10d ~]# su - devlab
[devlab@centos-10d ~]$ sudo -i
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for devlab:
[sudo] password for devlab: 
[root@centos-10d ~]# whoami
root

[root@centos-10d ~]# su devlab
[devlab@centos-10d root]$ 
[devlab@centos-10d root]$ sudo ls -la /root
total 24


Leave a Reply

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