User and Group
Update USER and GROUP with real value.
Create User
CentOS and Ubuntu
USER=username
sudo useradd $USER
sudo usermod -aG wheel $USER
USER=username
PASSWORD=password
useradd -m -s /bin/bash -p $(openssl passwd -1 $PASSWORD) $USER
usermod -aG sudo $USER
Ubuntu
USER=username
sudo adduser --gecos "" $USER
sudo usermod -aG sudo $USER
USER=username
PASSWORD=password
useradd -m -s /bin/bash -p $(openssl passwd -1 $PASSWORD) $USER
usermod -aG sudo $USER
Password less sudo command execution
USER=username
sudo tee -a /etc/sudoers.d/$USER << EOF
$USER ALL=(ALL) NOPASSWD: ALL
EOF
Sometimes user needs to logout and re-login to update the group. Or follow this to reload users groups without logging out.
logout
Create Group
CentOS and Ubuntu
sudo groupadd GROUP
Ubuntu
sudo addgroup GROUP
Update User
Add users to group
sudo usermod -aG GROUP USER
sudo gpasswd -a USER GROUP
Update user password
sudo passwd USER
Remove user from a group
sudo gpasswd -d USER GROUP
Update user default shell
sudo usermod -s /bin/bash USER
sudo usermod -s /usr/sbin/nologin USER
Delete password
sudo passwd -d USER
Delete User
CentOS and Ubuntu
sudo userdel USER
Ubuntu
sudo deluser USER
Delete user files
sudo rm /home/USER -rf
Delete Group
CentOS and Ubuntu
sudo groupdel GROUP
Ubuntu
sudo delgroup GROUP