-
List all users
cat /etc/passwdIt’s the first column. Orawk -F : ‘{print $1, “uid=”$3, “gid=”$3}’ /etc/passwd -
List the default settings for adding a new user
useradd -DThe shell will often be just/bin/sh, which is not what you want -
Add a new user
sudo useradd -c “Joe Bloggs” -m -s “/bin/bash” jbloggsthensudo passwd jbloggsto set his password. If you set it to something simple, then usesudo passwd -e USERthey will have to change their password on first login. -
Login as another user
su jbloggs -
Delete a user, including their home directory
sudo userdel -r USER. The commanddelusercan remove all files owned by the user as well. -
Lock and unlock an account
sudo usermod -L USERandsudo usermod -U USER -
Set an account to expire on a date
sudo usermod -e 2018-08-14 -
Create and delete groups
sudo groupadd GROUPandsudo groupdel GROUP -
Add a user into some more groups
sudo usermod -a -G ADDITIONALGROUPs USER -
Specify exactly the groups a user is a member of
sudo usermod -G GROUP1,GROUP2,GROUPN USER. If the user is a member of a group not specified then they will be removed from that group. -
Remove a user from a group
sudo deluser USER GROUP -
Enable a user to do sudo
usermod -a -G sudo USER -
List groups a user is a member of
groups USERor justgroupsfor your own account. To see the numerical Ids as well, doid USER.