Ubuntu admin—users and groups

It seems that I do admin for Ubuntu users and groups just infrequently enough, that every time I have to go look this stuff up and decide which to use. So I collected it in one place that I should be able to find next time.  I put it here just in case it might help someone else in the meanwhile.

These work in Ubuntu, at least (the only Linux distribution I care about this afternoon).

This list uses usr and grp to stand in for the actual user name and group name.

List users
cat /etc/passwd

Add user
sudo adduser usr
It asks for the other info it wants, sets up the home dir, etc.  If you just want a bare id, try useradd (sorry, go look it up)

Remove user
sudo deluser usr
Also remove /home/usr if you need to.

List groups
cat /etc/group

Add group
sudo addgroup grp

Remove group
sudo delgroup grp

What groups is user in
groups usr

What users are in group
grep grp /etc/group

Add user to group
sudo adduser usr grp

Remove user from group
sudo deluser usr grp

Change user’s primary group
sudo usermod -g grp usr

There are other programs you could install (on each server) that are friendlier than grep and cat.

Note that changes to group membership only take effect upon login.  If you’re the user, you’ll have to log out and log back in again.

Leave a Reply

Your email address will not be published. Required fields are marked *