Groups for Teamwork
A shared folder.
Sam and Alex are building a website together, and both need to edit the same files. Giving everyone access would be unsafe. The clean way is a group.

- Two people, the same files
- Everyone? Unsafe
- Use a group
Make a group, add people
Sudo group add web creates a group called web. Then user mod dash AG web adds Sam, and Alex, to it. Dash A means append, so they keep their other groups. Forgetting the A would remove them from their other groups. Get ent group web lists the members.
sudo groupadd web sudo usermod -aG web sam sudo usermod -aG web alex getent group web web:x:1002:sam,alex
A shared folder
Now a shared folder. We create slash srv slash site, give it to the web group, and set the permissions to seven seven zero. Owner and group can do everything, others nothing. Alex creates a file there, no problem. But when Sam tries to list the folder, permission denied! Sam is in the group, but this terminal was opened before Sam joined it.
sudo mkdir /srv/site sudo chgrp web /srv/site sudo chmod 770 /srv/site sudo -u alex touch /srv/site/index.html ls -l /srv/site ls: cannot open directory '/srv/site': Permission denied
One gotcha
That's the gotcha. After you're added to a group, your current terminal doesn't know yet. You need to log out and back in, before the new group works for you. Then Sam can use the folder too. That surprises everyone the first time.
| key | value |
|---|---|
| groupadd | create a group |
| usermod -aG | add members, keep others |
| chgrp + chmod 770 | shared folder |
| Log out and in | to pick up new groups |
Summary
A group, plus a folder owned by that group, with seven seven zero, lets a team share files safely. Next, a permissions challenge.
Key takeaways- sudo groupadd web
- usermod -aG web user
- chgrp + chmod 770