1. Accounts and groups #
Who can log in and with which identity.
Account files #
| File | Content |
|---|---|
/etc/passwd | name:x:UID:GID:comment:directory:shell (readable by everyone) |
/etc/shadow | password hashes and expiry (root only) |
/etc/group | groups 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é, historiqueGroups #
sudo groupadd devs
sudo gpasswd -d alice docker # retirer d'un groupe
newgrp devs # activer un nouveau groupe sans se reconnecterCommon mistake:usermod -G devs alicewithout-areplaces all of alice's secondary groups: she loses, for example, thesudogroup.
2. sudo #
Delegating root rights without sharing the password.
Principle #
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 sudoRules #
# /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.shGood practice: Grant specific commands rather thanALL, and never allow an editor,lessor 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 #
| Permission | On a file | On a directory |
|---|---|---|
| r (4) | read the content | list the names |
| w (2) | modify | create, rename, delete files |
| x (1) | execute | traverse (cd, access files) |
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épertoiresumask #
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 session4. Special permissions, ACLs and attributes #
When rwx is not enough.
SUID, SGID and sticky bit #
| Bit | Notation | Effect |
|---|---|---|
| SUID (4000) | rws------ | the program runs with its owner's rights (e.g. passwd) |
| SGID (2000) on a directory | rwxrws--- | created files inherit the directory's group: ideal for a team folder |
| Sticky (1000) | rwxrwxrwt | only 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)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 ACLAttributes #
sudo chattr +i /etc/resolv.conf # immuable, même pour root
sudo chattr +a /var/log/audit.log # ajout uniquement
lsattr /etc/resolv.confMy progress
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.
Recommended Articles
Users, groups, NTFS permissions and SMB shares
Manage local accounts and groups, understand UAC, apply NTFS permissions with inheritance, create...
Linux administration best practices
Checklist for administering Linux servers: accounts and sudo, SSH, updates, systemd services, sto...
Linux vs Unix: the complete guide to commands and distributions
Understand the differences between Linux and Unix, explore distributions (server, desktop, lightw...
Dynatrace: managing permissions (IAM, groups, policies and boundaries)
Manage access in Dynatrace: the IAM model (users, groups, policies, boundaries), default policies...
Storage on Linux: disks, partitions, file systems and LVM
Administer Linux storage: lsblk and blkid, GPT partitioning, ext4 and XFS, mounting and /etc/fsta...
Networking on Linux: configuration, diagnosis, firewall and SSH
Configure and troubleshoot Linux networking: ip, ss, netplan and NetworkManager, DNS, layered dia...
Linux server security and hardening
Harden a Linux server: least privilege, updates, secure SSH, firewall, fail2ban, SELinux and AppA...
The Bash shell and files: navigation, redirections, pipes and text processing
Master the Linux command line: paths, file handling, wildcards, redirections, pipes, searching wi...
Packages, systemd services, logs and scheduled tasks
Install and update software with apt and dnf, manage services with systemctl, write a systemd uni...