RousselTMLEARNING

Article · Linux administration: from discovery to expertise

Users, groups, sudo and permissions

1. Accounts and groups #

Who can log in and with which identity.

Account files #

FileContent
/etc/passwdname:x:UID:GID:comment:directory:shell (readable by everyone)
/etc/shadowpassword hashes and expiry (root only)
/etc/groupgroups and secondary members
/etc/sudoers, /etc/sudoers.d/sudo rules

Each account has a UID: 0 for root, below 1000 for system accounts (services), 1000 and above for humans. Services run under system accounts without a shell (/usr/sbin/nologin) to limit damage in case of compromise.

Managing accounts #

sudo useradd -m -s /bin/bash -c "Alice Martin" alice   # créer avec répertoire personnel
sudo passwd alice                     # définir le mot de passe
sudo usermod -aG devs,docker alice    # ajouter à des groupes (-a indispensable !)
sudo chage -M 90 -W 7 alice           # expiration du mot de passe à 90 jours
sudo chage -l alice                   # politique d'expiration
sudo usermod -L alice                 # verrouiller ; -U pour déverrouiller
sudo userdel -r bob                   # supprimer avec son répertoire
sudo useradd -r -s /usr/sbin/nologin -d /srv/app app   # compte de service
id alice ; groups alice ; getent passwd alice
who ; w ; last -n 10 ; lastlog         # qui est connecté, historique

Groups #

sudo groupadd devs
sudo gpasswd -d alice docker   # retirer d'un groupe
newgrp devs                    # activer un nouveau groupe sans se reconnecter
Common mistake: usermod -G devs alice without -a replaces all of alice's secondary groups: she loses, for example, the sudo group.

2. sudo #

Delegating root rights without sharing the password.

Principle #

How sudo works
Each command is attributed to a person: traceability is preserved.

sudo runs a command under another identity (root by default) after authenticating the user, and logs every command. You never log in directly as root: everyone uses their named account, which keeps traceability.

sudo -l                          # ce que j'ai le droit de faire
sudo -i                          # shell root (journalisé)
sudo -u postgres psql            # exécuter en tant qu'un autre utilisateur
sudo visudo -f /etc/sudoers.d/devs   # éditer avec vérification de syntaxe
journalctl _COMM=sudo --since today  # audit des commandes sudo

Rules #

# /etc/sudoers.d/devs
# utilisateur/groupe  hôtes=(identité)  commandes
%sudo   ALL=(ALL:ALL) ALL
%devs   ALL=(root) /usr/bin/systemctl restart app, /usr/bin/journalctl -u app*
deploy  ALL=(root) NOPASSWD: /usr/local/bin/deploy.sh
Good practice: Grant specific commands rather than ALL, and never allow an editor, less or a user-modifiable script through sudo: they make it possible to get a root shell.
Common mistake: Always edit with visudo: a syntax error in sudoers can block all root access.

3. Permissions #

Read, write, execute.

Reading permissions #

Breakdown of permissions
r = 4, w = 2, x = 1: add them up for each category.
PermissionOn a fileOn a directory
r (4)read the contentlist the names
w (2)modifycreate, rename, delete files
x (1)executetraverse (cd, access files)
Order in which permissions are evaluated
An owner with r-- cannot write, even if the group has rw-.

Changing them #

chmod 640 secret.conf            # rw- r-- ---
chmod u+x deploy.sh              # ajouter l'exécution au propriétaire
chmod -R g+rwX /srv/projet       # X : exécution seulement sur les répertoires
sudo chown alice:devs fichier    # changer propriétaire et groupe
sudo chown -R www-data: /srv/www # groupe principal de l'utilisateur
find /srv -type d -exec chmod 2775 {} +   # appliquer aux seuls répertoires

umask #

The umask removes permissions from created files. With umask 022, a file is created as 644 and a directory as 755; with 027, as 640 and 750 (nothing for others).

umask ; umask 027   # valeur courante, puis plus restrictive pour la session

4. Special permissions, ACLs and attributes #

When rwx is not enough.

SUID, SGID and sticky bit #

BitNotationEffect
SUID (4000)rws------the program runs with its owner's rights (e.g. passwd)
SGID (2000) on a directoryrwxrws---created files inherit the directory's group: ideal for a team folder
Sticky (1000)rwxrwxrwtonly the owner can delete their files (e.g. /tmp)
sudo chmod 2770 /srv/equipe            # dossier partagé avec héritage du groupe
find / -xdev -perm -4000 -type f 2>/dev/null   # inventaire des binaires SUID (audit)
Group inheritance with SGID
With a 002 umask, all members of devs can modify the team's files.

ACLs #

ACLs grant permissions to additional users or groups, without changing the owner. A + at the end of the permissions in ls -l signals an ACL.

setfacl -m u:bob:rx /srv/rapports          # droit pour bob
setfacl -d -m g:audit:r /srv/rapports      # ACL par défaut, héritée par les nouveaux fichiers
getfacl /srv/rapports
setfacl -b /srv/rapports                   # supprimer toutes les ACL

Attributes #

sudo chattr +i /etc/resolv.conf   # immuable, même pour root
sudo chattr +a /var/log/audit.log  # ajout uniquement
lsattr /etc/resolv.conf

📄 Users, groups, sudo and permissions on Linux →

My progress

  • ⏱ Estimated time : ≈ 8 min

Sign in to track your progress and take notes. Sign in

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

Bash scripts for administrators: writing robust scripts

Automate Linux administration with Bash: variables and quoting, conditions, loops, functions, exi...

Linux system architecture: kernel, boot and directory tree

Understand how a Linux server works: kernel and user space, the UEFI, GRUB, initramfs and systemd...

Backup, monitoring and troubleshooting of a Linux server

Operate a Linux server day to day: 3-2-1 backup strategy with rsync, tar, LVM snapshots and resti...

Microsoft Entra ID, RBAC and Azure Policy: identities, permissions and governance

Manage identities and access on Azure: Microsoft Entra ID (users, groups, MFA, conditional access...

Processes, memory and performance: monitoring and troubleshooting a Linux server

Understand and control Linux processes (ps, top, signals, nice, jobs), interpret load, memory and...

Grafana administration and security: organizations, teams, RBAC, service accounts and authentication

Running Grafana in a company: organizations, teams, folders, roles and RBAC, data source permissi...

Ansible: managing security (Vault, SSH, privileges and secrets)

Securing Ansible: Ansible Vault, SSH key authentication, become and sudo, no_log, hardening the c...

Identities and access on OVHcloud: account, IAM, OpenStack users and keys

Secure access to OVHcloud: two-factor authentication on the account, OVHcloud IAM (identities, po...

Ansible: the inventory (static, dynamic, groups and variables)

Understand and master the Ansible inventory: INI and YAML files, groups, host and group variables...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!