Changing ownership: chown and chgrp
You hand the finance team’s files to the right person and group: change owners and groups, hand over directories, add a new member to the team and remove someone added by mistake; you find and fix an invoice left open to everyone and produce an ownership report.
Level 101 · 45 min
The finance team’s files were moved to /srv/finance, but they all still belong to root. The team has Daniel (deniz, who owns the budget) and Elif (elif); both are members of the finance group. Barış (baris) joins the team this week. Can (can) from the sales team must not see these files.
Permissions are written for "owner, group, others", but the file’s ownership says who the owner and the group are. chown (change owner) changes the owner and chgrp (change group) the group. Only root can change ownership.
An analogy: a permission says “the family may enter this room”, ownership answers “who is this house’s family”. Group membership is the family list: if the wrong person is written on it, every door opens for them too.
What you will do in this lesson
- Whose file is it? ls -l and stat
- Change the owner: chown
- Change the group and test: chgrp
- Hand over a directory with its contents: chown -R
- Close the directory to everyone but the team
- A new member: add to the group, test with a new session
- The wrong person is on the list: gpasswd -d
- Invoices: find the odd file out and fix it
- The ownership report
- Short quiz
Skills you will earn
- Reading owner, group and mode with stat
- Changing a file’s owner (chown)
- Changing a file’s group (chgrp)
- Testing a setting as another user (su -c)
- Handing over a directory with its contents (chown -R user:group)
- Knowing what r, w and x mean on directories
- Adding a user to a group safely (usermod -aG)
- Knowing group membership takes effect in a new session
- Removing a person from one group (gpasswd -d)
- Finding odd files by owner and permission (find -user, -perm)
- Producing a folder’s ownership report (find -exec stat)
← File permissions: read, write, execute and chmod · Linux quick start · Quick task: lock down a team folder left wide open →
Start for free