2.10.6. Understanding Ownership and Group Ownership¶
Linux for Programmers and Users, Sections 3.27, 3.28, 3.29
We have seen from the output of ls -l
(see Directory Contents (ls)),
that each file has an owner and a group owner.
Note
A group is a collection of users that can potentially share
files with each other that are not shared with everyone. Groups are
usually defined in the /etc/group
file.
File permissions are grouped by three classes of users:
- Owner of the file
- Group Owners
- Others
In the output of ls -l
, the middle set of permissions for
read, write and execute are group permissions.
Entry for romeo in /etc/passwd
:
romeo:x:1003:1003::/home/romeo:/usr/bin/ksh
Entry for romeo’s group (1003) in /etc/group:
romeo::1003:
Here romeo is in a group by himself. This is a common practice, as it keeps files with liberal group permission from being shared with others unintentionally. Our user romeo may also be in other groups so that select files and directories may shared with colleagues.
2.10.6.1. groups¶
-
groups
Lists names of groups that the user is in.
SYNOPSIS
groups [USERNAME]…
$ groups
romeo tailgaters shakespeare
$ getent group shakespeare
shakespeare:x:3023:romeo,juliet
Note
How does ls -l
print the name of the owner and group owner? If
a file foo is owned by romeo and group owned by users, the inode
for foo stores 1003 and 101 as the UID and GID, respectively.
ls first looks up the inode for these two parameters and then
translates them to their name representation using /etc/passwd and
/etc/group.
Why doesn’t romeo’s name appear in the entry in /etc/group?