AI Hints
Home›Linux Tutorial›Managing Users
Linux · Lesson 72 of 120

Groups for Teamwork

A shared folder.

⏱ 2 min read▶ Video at 1:34:43🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

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.

Groups for Teamwork
From the video: Groups for Teamwork
  • 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.

Terminal
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.

Terminal
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.

keyvalue
groupaddcreate a group
usermod -aGadd members, keep others
chgrp + chmod 770shared folder
Log out and into 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
Next up: Practice: Permission Problems — fix the problems