The owner of a file can extend read and write permission to just the group.
You may not want to give all users permission to read a file. If you only want to give permission to other people in the file’s group, you can use the g+r syntax instead:
% chmod g+r filename
Instead of giving permission to all users (a), you are giving permission to just the group (g). Similarly, you can give write permission to others in the group with g+w:
% chmod g+w filename
and both read and write permission with g+rw:
% chmod g+rw filename
For example, suppose my coworker Mike wants to edit a file of mine called updates. I can let him do this by giving read and write permission to the world with chmod a+r, but it’s safer to give permission only to members of the file’s group, if you can.
If I run ls -lg on updates, I’ll see that it belongs to the group prod, but is read/write only to the owner, lmui (me).
% ls -lg updates
-rw------ 1 lmui prod 249 Oct 25 09:24 updatesI can check that Mike belongs to the prod group by using the groups command:
% groups mike mike : ora prod
So I don’t have to give read ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
