Users and Groups

Users and groups allow structuring and securing system access, whether for people or system processes.

User: definition

A user under Linux is an entity that can connect to the system and execute commands. Each user has a unique identifier called UID (User ID). System users, on the other hand, do not connect directly and generally have a UID below 1000, although this may vary depending on distributions (for example, on some distributions, human users start from 500).

There are different types of users:
  • root: administrator user with all privileges. We speak of superuser.
  • System users: created to run services (ex: www-data, nobody).
  • Human users: created for people interacting directly with the system.

Group: definition

A group is a set of users who share permissions. Groups simplify access management to certain files or directories.

For example, a developers group to which several users belong can be used to give access to a shared directory containing source code.


Creating users and groups

Key commands

These commands are those used on the Alpine Linux distribution (of which we use an emulator in class). They are not always available, and it will be appropriate to search, depending on the distribution used, for the appropriate commands.
  • adduser: creates a user (man).
  • deluser: deletes a user (man).
  • addgroup: creates a group (man).
  • delgroup: deletes a group (man).
  • groups [user]: displays groups associated with the user (replace [user] with a username)

Example scenario

Imagine we want to create accounts for four users, then add them to the nsi group.

This will create the following directories:
/home
├── nono
├── toto
├── nana
└── didi
# addgroup nsi
# adduser nono
# adduser toto
# adduser nana
# adduser didi
# adduser nono nsi
# adduser toto nsi
# adduser nana nsi
# adduser didi nsi