Users and groups: the files behind them
Video 110 of 140 in Virtualization Foundations, in the unit “Users, groups, permissions and sudo”. 2:49, with English and Hindi audio.
Every program on a Linux machine runs as some user, and every file belongs to a user and to a group. So where does Linux keep the list of those names? The answer is three plain text files in the etc folder. This article explains what a user and a group are, what each of the three files holds, and why giving rights to a group is simpler than giving them to each person. Knowing these files helps you check an account when something looks wrong.
What you will learn
- A user is an account, known by a name and by a number, and it may belong to a person or to a service.
- A group is a named list of users, so a right given to the group reaches every member at once.
- The passwd file holds account details and can be read by anyone, and the group file holds the members of each group.
- The shadow file holds the password hashes, and only root and the shadow group can read it.
- An x in the passwd file means the password hash is kept in the shadow file.
Users and groups are two kinds of owner
A user is an account. It may belong to a person, such as alice, or to a program, such as a web server. Linux knows that account by a name and by a number.
A group is a named list of users. If a folder gives its rights to a group, every member gets them at once. Nobody has to be added to the folder one by one.
The three files that keep the lists
- passwd: the account names, numbers, home folders and login shells. Anyone may read it.
- group: the group names, their numbers, and the members of each group.
- shadow: the password hashes. Only root and the shadow group can read it, so nobody can copy the hashes to guess passwords elsewhere.
Linux keeps these lists as plain text files in the etc folder. Each line in them is one record. Change them only with the proper commands, and keep a backup copy ready.
Reading one passwd entry
getent passwd www-dataThe entry shows the name www-data and the user number 33. The home folder is /var/www, and the shell is nologin, so nobody can open an interactive session as this account. The x after the name means the password hash is kept in the shadow file, not here.
Adding someone to a group
Picture a small team. Alice and Bob both belong to the group called devs, and the group holds the rights to a shared folder. When Carol joins devs, she does not get a copy of the folder's rights. She simply becomes a member of the group, and the rights already apply to her.
Note: Membership is a change to the group file. It counts only when that person logs in again, not in a session that is already open.
Terms
- User account
- An account on the machine, known by a name and a number, under which programs and people run.
- Group
- A named list of users, so that rights given to the group apply to every member at once.
- Password hash
- A scrambled form of a password, stored in the shadow file so that the password itself is not kept.
Check yourself
Which file holds the password hashes, and who can read it?
The shadow file. Only root and the shadow group can read it.
What does the x in a passwd entry mean?
The password hash is kept in the shadow file, not in the passwd file.
Why is a group easier than adding each person to a folder?
Rights given to a group apply to every member at once. A new member gets them when they join the group, with no change to the folder.
Previous: History, completion and shortcuts. Next: Who am I? The id and whoami commands.