How to add sudo user on CentOS 7

Scenario: add sudo user on CentOS 7
System: CentOS 7

Steps to Create a New Sudo User
– Log in to your server as the root user.
– Use the adduser command to add a new user to your system,example add user with username bachem.

[root@horse ~]# useradd bachem
[root@horse ~]# passwd bachem
Changing password for user bachem.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@horse ~]#

– By default, on CentOS, members of the wheel group have sudo privileges,use the usermod command to add the user bachem to the wheel group.

[root@horse ~]# usermod -aG wheel bachem

– Test sudo access on new user account, use the su command to switch to the new user account.
As the new user, verify that you can use sudo by prepending “sudo” to the command that you want to run with superuser privileges.
The first time you use sudo in a session, you will be prompted for the password of the user account. Enter the password to proceed.
If your user is in the proper group and you entered the password correctly, the command that you issued with sudo should run with root privileges.

[bachem@horse ~]$ sudo yum update

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 bachem:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.delorahosting.com
 * extras: mirror.delorahosting.com
 * updates: mirror.delorahosting.com
No packages marked for update
[bachem@horse ~]$

Related posts:

Leave a Reply

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