Linux is built for many users at once. Every file has an owner and every process runs as somebody, so the system needs a way to name those identities.
Users and UIDs
Each account has a name and a number called the UID. The kernel works with the number. The name is for people.
$ id
uid=1000(maya) gid=1000(maya) groups=1000(maya),27(sudo),1002(devs)There are three kinds of account you will meet:
- root, UID 0, the administrator
- system accounts, used by services such as a web server or a mail daemon
- regular users, for people, usually numbered from 1000
The exact ranges are set per distribution, often in /etc/login.defs.
Groups
A group is a named set of users, with its own number called the GID. Groups let you grant access to several people at once: give a directory to group devs, and every member can use it according to the group permissions.
Each user has one primary group, which new files normally receive, and any number of supplementary groups. Many distributions give each new user a private primary group with the same name. Others may use a shared group such as users.
Looking things up
$ groups
maya sudo devs
$ whoami
maya
$ getent passwd maya
maya:x:1000:1000:Maya Rao:/home/maya:/bin/bash
$ getent group devs
devs:x:1002:maya,liamgetent asks the system's configured sources, so it also finds accounts that come from a network directory such as LDAP, not only those in local files.
Group membership is read when a session starts. If you are added to a group, log out and in again before expecting the new access.
Why it matters
Separate accounts limit damage. A web server that runs as its own user cannot read your private files unless the permissions allow it. Separate accounts also let logs show who did what.
Try it
$ id
$ id root
$ getent passwd | head -n 5
$ getent group | wc -lFind your primary group, then list your supplementary ones. Compare your UID with the UIDs of the first few accounts. You can go further in the accounts and access files lab.
Check your understanding
Users and Groups
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.