Linux System Administration: The Complete Guide
Learn Linux system administration: users, systemd services, processes, disk and memory monitoring, logs, cron, and rsync backups.
InSkillCoach
Linux System Administration: The Complete Guide
Administering a Linux system is much more than typing a few commands into a terminal. It means understanding how users, services, processes, and storage interact, and knowing how to step in quickly when something stops working. In this guide, we cover the seven pillars of system administration: user management, systemd services, processes, resource monitoring, logs, task scheduling, and backups. Each section contains real commands that you can run on any modern distribution (Debian, Ubuntu, Rocky Linux, Fedora).
1. User and Group Management
Creating and modifying users
The useradd command creates a user. On most distributions, remember the -m option to create the home directory.
# Créer un utilisateur avec son répertoire personnel et un shell bash
sudo useradd -m -s /bin/bash alice
# Définir son mot de passe
sudo passwd alice
# Vérifier les informations d'un utilisateur
id alice
getent passwd alice
The usermod command modifies an existing account:
# Ajouter alice au groupe docker (l'option -a est indispensable pour ne pas
# écraser les groupes existants)
sudo usermod -aG docker alice
# Changer le shell de connexion
sudo usermod -s /bin/zsh alice
# Verrouiller un compte (interdit la connexion par mot de passe)
sudo usermod -L alice
# Déverrouiller le compte
sudo usermod -U alice
# Définir une date d'expiration du compte
sudo usermod -e 2026-12-31 alice
Managing groups
# Créer un groupe
sudo groupadd developpeurs
# Lister les groupes d'un utilisateur
groups alice
# Supprimer un utilisateur d'un groupe
sudo gpasswd -d alice docker
# Supprimer un groupe
sudo groupdel developpeurs
Configuring sudo properly
Never edit /etc/sudoers directly with a regular editor: a syntax error can lock you out of root access. Always use visudo, which validates the syntax before saving.
# Éditer le fichier sudoers en toute sécurité
sudo visudo
# Bonne pratique : créer un fichier dédié dans /etc/sudoers.d/
sudo visudo -f /etc/sudoers.d/alice
Examples of sudoers rules:
# Donner tous les droits à alice (avec mot de passe)
alice ALL=(ALL:ALL) ALL
# Autoriser le groupe admin à tout faire
%admin ALL=(ALL) ALL
# Autoriser alice à redémarrer nginx sans mot de passe, et rien d'autre
alice ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx
2. systemd Services
systemctl: the orchestrator
systemd is the init system of nearly all current distributions. The systemctl command controls services (called units).
# Démarrer, arrêter, redémarrer un service
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
# Recharger la configuration sans couper le service (si supporté)
sudo systemctl reload nginx
# Activer le démarrage automatique au boot
sudo systemctl enable nginx
# Activer et démarrer en une seule commande
sudo systemctl enable --now nginx
# Vérifier l'état détaillé
systemctl status nginx
# Lister toutes les unités en échec
systemctl --failed
# Lister tous les services actifs
systemctl list-units --type=service --state=running
Anatomy of a systemd unit
Custom units go in /etc/systemd/system/. Here is a minimal service for an application:
# /etc/systemd/system/monapp.service
[Unit]
Description=Mon application web
After=network.target
[Service]
Type=simple
User=monapp
WorkingDirectory=/opt/monapp
ExecStart=/opt/monapp/bin/serveur --port 8080
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
After any change to a unit file, reload the daemon:
# Prendre en compte les nouveaux fichiers d'unités
sudo systemctl daemon-reload
sudo systemctl enable --now monapp
journalctl: reading service logs
# Journaux d'un service précis
journalctl -u nginx
# Suivre les journaux en temps réel (équivalent de tail -f)
journalctl -u nginx -f
# Journaux depuis le dernier démarrage
journalctl -b
# Journaux des deux dernières heures
journalctl --since "2 hours ago"
# Filtrer par niveau de gravité (erreurs et pire)
journalctl -p err -b
3. Process Management
Observing processes
# Vue complète de tous les processus
ps aux
# Arborescence des processus (qui a lancé quoi)
ps auxf
# Vue temps réel classique
top
# Vue temps réel améliorée (à installer : apt install htop)
htop
# Trouver le PID d'un processus par son nom
pgrep -a nginx
Priorities: nice and renice
A process’s priority ranges from -20 (highest priority) to 19 (lowest priority). Only root can assign a negative value.
# Lancer une compression avec une priorité basse pour ne pas gêner le système
nice -n 19 tar -czf /backup/archive.tar.gz /var/www
# Changer la priorité d'un processus déjà lancé (PID 4321)
sudo renice -n 10 -p 4321
Terminating a process
# Demander l'arrêt propre (SIGTERM, signal 15)
kill 4321
# Forcer l'arrêt (SIGKILL, signal 9) : en dernier recours uniquement
kill -9 4321
# Tuer tous les processus portant un nom donné
pkill -f "python script_bloque.py"
# Envoyer un signal de rechargement de configuration
kill -HUP 4321
4. Disk and Memory Monitoring
Disk space: df and du
# Occupation de tous les systèmes de fichiers, en unités lisibles
df -h
# Occupation des inodes (un disque peut être plein d'inodes avec de l'espace libre)
df -i
# Taille totale d'un répertoire
du -sh /var/log
# Les 10 plus gros sous-répertoires de /var
du -h --max-depth=1 /var | sort -rh | head -10
Memory: free
# État de la mémoire en unités lisibles
free -h
# Rafraîchir toutes les 5 secondes
free -h -s 5
Pay attention to the available column rather than free: Linux uses unused memory as a disk cache, and this cache is released automatically when applications need it. Memory that is “full” of cache is normal, healthy behavior.
Disk I/O: iostat
iostat is part of the sysstat package (sudo apt install sysstat).
# Statistiques d'E/S étendues, rafraîchies toutes les 2 secondes
iostat -x 2
# Se concentrer sur un disque précis
iostat -x 2 /dev/sda
The columns to watch: %util (disk saturation; close to 100% = bottleneck) and await (average request wait time in milliseconds).
5. Logs: journald and logrotate
Controlling the size of journald
By default, journald can take up a significant amount of space in /var/log/journal. Limit it in /etc/systemd/journald.conf:
# /etc/systemd/journald.conf
[Journal]
SystemMaxUse=500M
MaxRetentionSec=1month
# Appliquer la configuration
sudo systemctl restart systemd-journald
# Vérifier l'espace occupé par les journaux
journalctl --disk-usage
# Purger manuellement au-delà de 200 Mo
sudo journalctl --vacuum-size=200M
logrotate for traditional log files
Applications that write to /var/log (nginx, custom applications) should be managed by logrotate. Example configuration in /etc/logrotate.d/monapp:
# /etc/logrotate.d/monapp
/var/log/monapp/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
create 0640 monapp monapp
postrotate
systemctl reload monapp > /dev/null 2>&1 || true
endscript
}
# Tester la configuration sans rien modifier
sudo logrotate -d /etc/logrotate.d/monapp
# Forcer une rotation immédiate
sudo logrotate -f /etc/logrotate.d/monapp
6. Scheduled Tasks: cron and systemd Timers
cron: the classic method
# Éditer la crontab de l'utilisateur courant
crontab -e
# Lister les tâches planifiées
crontab -l
Syntax of a cron line: minute hour day_of_month month day_of_week command.
# Sauvegarde tous les jours à 2h30
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
# Nettoyage tous les dimanches à 4h
0 4 * * 0 find /tmp -type f -mtime +7 -delete
# Toutes les 15 minutes
*/15 * * * * /usr/local/bin/verifier-service.sh
systemd timers: the modern alternative
Timers provide logging through journalctl, dependency management, and catch-up of missed runs (Persistent=true). You need two files: a service and a timer.
# /etc/systemd/system/backup.service
[Unit]
Description=Sauvegarde quotidienne
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
# /etc/systemd/system/backup.timer
[Unit]
Description=Déclenche la sauvegarde quotidienne
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
[Install]
WantedBy=timers.target
# Activer le timer et vérifier la prochaine exécution
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
systemctl list-timers backup.timer
| Criterion | cron | systemd timer |
|---|---|---|
| Simplicity | One line is enough | Two unit files |
| Logging | You manage it yourself | Built into journalctl |
| Catch-up if machine was off | No (except anacron) | Yes with Persistent=true |
| Dependencies between tasks | No | Yes (After=, Requires=) |
| Precision | To the minute | To the second |
7. Backups: rsync and tar
rsync: incremental synchronization
rsync transfers only the differences, which makes it ideal for regular backups, both locally and remotely.
# Sauvegarde locale : -a préserve permissions, dates et liens ; -v verbeux
rsync -av /var/www/ /backup/www/
# Simulation sans rien copier (toujours tester d'abord)
rsync -avn --delete /var/www/ /backup/www/
# Miroir exact : --delete supprime dans la destination ce qui a disparu de la source
rsync -av --delete /var/www/ /backup/www/
# Sauvegarde distante via SSH avec exclusions
rsync -av --delete \
--exclude 'cache/' \
--exclude '*.tmp' \
-e "ssh -p 2222" \
/var/www/ backup@serveur-backup:/backups/www/
Watch out for the trailing slash: /var/www/ copies the contents of the directory, whereas /var/www copies the directory itself into the destination.
tar: full archives
# Créer une archive compressée horodatée
tar -czf /backup/www-$(date +%Y%m%d).tar.gz /var/www
# Lister le contenu sans extraire
tar -tzf /backup/www-20260917.tar.gz
# Extraire dans un répertoire précis
tar -xzf /backup/www-20260917.tar.gz -C /tmp/restauration
# Archive avec compression zstd (plus rapide que gzip)
tar --zstd -cf /backup/www.tar.zst /var/www
Verifying your backups
An untested backup is not a backup. Schedule regular test restores:
# Restaurer dans un répertoire temporaire et comparer avec la source
mkdir /tmp/test-restauration
tar -xzf /backup/www-20260917.tar.gz -C /tmp/test-restauration
diff -r /tmp/test-restauration/var/www /var/www
Best Practices
- Always use
visudoto modify the sudo configuration, and prefer dedicated files in/etc/sudoers.d/. - Grant the most restrictive sudo rights possible: a specific command rather than
ALL. - After every change to a systemd unit, run
systemctl daemon-reload, then verify withsystemctl status. - Prefer
kill(SIGTERM) overkill -9: give processes a chance to shut down cleanly. - Monitor inodes (
df -i) as much as disk space: a system can be blocked even with free space. - Limit the size of journald and set up logrotate as soon as you install a new service.
- Redirect the output of your cron jobs to a log file, or use systemd timers to take advantage of journalctl.
- Apply the 3-2-1 rule for backups: three copies, two different media, one off-site copy.
- Test your restores regularly, not just your backups.
Conclusion
Linux system administration relies on a small number of fundamental tools that you will use daily: useradd and visudo for accounts, systemctl and journalctl for services, ps, top, and kill for processes, df, free, and iostat for resources, cron or systemd timers for automation, and rsync for backups. Mastering these tools lets you diagnose and resolve the vast majority of production incidents.
The logical next step is to automate: turn your manual interventions into scripts, then into scheduled tasks, then into configuration managed by tools like Ansible. A good system administrator is one who never performs the same operation by hand twice.
About InSkillCoach
Training and technology expert
Coach specializing in advanced technologies and AI, backed by GNeurone Inc.
Certifications:
- AWS Certified Solutions Architect – Professional
- Google Cloud certifications
- Microsoft Certified: DevOps Engineer Expert
- Certified Kubernetes Administrator (CKA)
- CompTIA Security+
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion