How to add/remove users, change password, create, edit groups and create sudo user on Debian linux?
List all local users
cat /etc/passwd
You could also use the following command to print only the username part of the above /etc/passwd
output.
cut -d: -f1 /etc/passwd
The above parameters: -d: use colon as the delimeter, -f1 get the first field.
You must be root for the following
su
Add new user
adduser username
Remove user
userdel username
User directory need to be deleted separately if required
rm -r /home/username
Edit username
usermod -l {new username} {old username}
Change password
passwd username
Create group
groupadd groupname
Add user to group
usermod -a -G groupname username
List all groups current user belongs to
groups
List all groups specific user belong to
groups username
List all groups
cut -d: -f1 /etc/group
Create sudo user
usermod -aG sudo username
Test sudo user
sudo ls -la /root
The above only works for root/sudo user
You will require to input the user password for the 1st time
If sudo command does not work you will need to install sudo package
apt install sudo