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

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...

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!