1. Package management #
Install, update, remove.
apt and dnf #
| Action | Debian / Ubuntu | RHEL / Rocky / Fedora |
|---|---|---|
| Update the index | apt update | dnf check-update |
| Upgrade the system | apt upgrade | dnf upgrade |
| Install | apt install nginx | dnf install nginx |
| Remove | apt remove / purge | dnf remove |
| Search | apt search | dnf search |
| Info | apt show | dnf info |
| Which package provides this file? | dpkg -S /usr/bin/ss | dnf provides /usr/bin/ss |
| Installed packages | dpkg -l / apt list --installed | rpm -qa |
| History | /var/log/apt/history.log | dnf history |
sudo apt update && sudo apt upgrade -y
apt list --upgradable
sudo apt autoremove # dépendances devenues inutiles
sudo apt-mark hold postgresql-16 # bloquer une version
cat /var/run/reboot-required 2>/dev/null # redémarrage nécessaire (noyau, libc)Repositories and automatic updates #
Packages come from signed repositories (/etc/apt/sources.list.d/, /etc/yum.repos.d/). Only add a third-party repository from the official vendor, with its GPG key.
sudo apt install unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgrades # Debian/Ubuntu
sudo dnf install dnf-automatic && sudo systemctl enable --now dnf-automatic.timer # RHELGood practice: Apply security fixes automatically, but schedule major upgrades (and reboots) in a maintenance window, first on a test server.
2. Services with systemd #
Start, stop, diagnose.
systemctl #
systemctl status nginx # état, PID, derniers logs
sudo systemctl start|stop|restart nginx
sudo systemctl reload nginx # relire la configuration sans couper
sudo systemctl enable --now nginx # activer au boot et démarrer
sudo systemctl disable nginx
systemctl is-active nginx ; systemctl is-enabled nginx
systemctl --failed # services en échec
systemctl list-units --type=service --state=running
systemctl cat nginx # fichier d'unité effectif
sudo systemctl edit nginx # surcharge (drop-in) sans toucher au paquet
sudo systemctl mask nginx # empêcher tout démarrageWriting a unit #
# /etc/systemd/system/app.service
[Unit]
Description=API de commandes
After=network-online.target
Wants=network-online.target
[Service]
User=app
WorkingDirectory=/srv/app
EnvironmentFile=/etc/app/app.env
ExecStart=/srv/app/bin/server --port 8080
Restart=on-failure
RestartSec=5
# Durcissement
NoNewPrivileges=true
ProtectSystem=strict
ReadWritePaths=/var/lib/app
PrivateTmp=true
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload # après toute modification d'unité
sudo systemctl enable --now app
systemd-analyze security app # score d'exposition du serviceGood practice: Never modify the files in/usr/lib/systemd/system(overwritten by updates): create an override withsystemctl edit.
3. Logs #
journald and the files in /var/log.
journalctl #
journalctl -u nginx -f # suivre un service
journalctl -u app --since "1 hour ago"
journalctl -p warning -b # avertissements et pires, depuis le boot
journalctl -k # messages du noyau
journalctl _PID=1234
journalctl -o json-pretty -n 1 # champs structurés
journalctl --disk-usage
sudo journalctl --vacuum-size=500M # limiter la tailleClassic files #
| File | Content |
|---|---|
/var/log/syslog or messages | general log (rsyslog) |
/var/log/auth.log or secure | authentications, sudo, SSH |
/var/log/kern.log | kernel |
/var/log/<service>/ | application logs (nginx, postgresql) |
logrotate rotates, compresses and deletes old files according to /etc/logrotate.d/.
# /etc/logrotate.d/app
/var/log/app/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
copytruncate
}sudo logrotate -d /etc/logrotate.d/app # simulation4. Scheduling tasks #
cron and systemd timers.
cron #
crontab -e # tâches de l'utilisateur
sudo crontab -l -u root
ls /etc/cron.d /etc/cron.daily# min heure jour mois jour_semaine commande
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
*/5 * * * * /usr/local/bin/check.sh
0 8 * * 1-5 /usr/local/bin/rapport.shCommon mistake: cron runs with a minimal environment (reduced PATH, no shell variables): use absolute paths and redirect the output, otherwise errors go unnoticed.systemd timers #
A timer triggers a service: you benefit from journald logs, dependencies, Persistent=true (catching up on a run missed during downtime) and a random delay.
# /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=Planification de la sauvegarde
[Timer]
OnCalendar=*-*-* 02:30
RandomizedDelaySec=15m
Persistent=true
[Install]
WantedBy=timers.targetsudo systemctl enable --now backup.timer
systemctl list-timers
systemd-analyze calendar 'Mon..Fri 08:00' # vérifier une expressionMy 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
The Bash shell and files: navigation, redirections, pipes and text processing
Master the Linux command line: paths, file handling, wildcards, redirections, pipes, searching wi...
Bash scripts for administrators: writing robust scripts
Automate Linux administration with Bash: variables and quoting, conditions, loops, functions, exi...
Processes, memory and performance: monitoring and troubleshooting a Linux server
Understand and control Linux processes (ps, top, signals, nice, jobs), interpret load, memory and...
Active Directory Domain Services and DNS
Understand and deploy Active Directory: forest, domains, organizational units, domain controllers...
HAProxy cheat sheet: the essential commands
A practical guide gathering all the essential commands to install, manage, test and debug HAProxy...
Fluent Bit: pipeline inputs in detail
Everything about Fluent Bit inputs: the role of tags, reading files with tail (positions, rotatio...
Windows networking: IP, DNS, DHCP, firewall and remote access
Configure and troubleshoot Windows networking with PowerShell, deploy a DHCP server, master Windo...
Grafana Alloy: collecting system metrics and local logs
Learn how to configure Grafana Alloy to monitor the server it runs on, with a focus on configurat...
Ansible: ad-hoc commands
Run immediate actions on a fleet of servers with ansible: the ping, command, shell, copy, apt, se...