Add & Delete Users in Linux
Last modified: 2023-10-30
We can easily add/delete users in Linux using `useradd`, `userdel` commands.
Add Users
We can use useradd
or adduser
command to add users in Linux.
useradd <user>
adduser <user>
# -p: Specify password
useradd <user> -p <password>
# -u: Specify UID
# -g: Specify GID
useradd -u 1000 -g 1000 <user>
Set Password for User
# Set passwords. It's stored in "/etc/shadow"
passwd <user>
Delete Users
We can use userdel
or deluser
command to delete users in Linux.
userdel <user>
deluser <user>
# -r: Remove home directory and mail spool
userdel -r <user>
List Users in Linux
To list users exist in Linux, run the following commands.
cat /etc/passwd
cat /etc/shadow
Allow Users to Run Commands as Root Privilege
Add users to the “sudo” group.
usermod -a -G sudo <user>
# Check the permissions
su <user>
sudo -l