add user to sudoers in centos code example

Example 1: create sudo user centos

Create a new user accoun: useradd username
Set the user password: passwd username
Add the new user to the sudo group: usermod -aG wheel username
su - username, then run, echo "username  ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/username

Example 2: Add User to Sudoers in CentOS

#create username and set password
useradd username
passwd username
#Verify the Wheel Group is Enabled
sudo visudo
%wheel        ALL=(ALL)       ALL
#Add User to Group
usermod -aG wheel username
# Open the Sudoers File in an Editor
sudo visudo
root ALL=(ALL) ALL
username ALL=(ALL) ALL
#Now you can switch to new username
su — username

Example 3: add user centos 7 sudo

useradd username
passwd username

Example 4: add user with sudoer centos

echo "username  ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/username

Example 5: add user with sudoer centos

username ALL=(ALL) NOPASSWD:/usr/bin/du,/usr/bin/ping