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
Services, scheduled tasks, event logs and performance
Control Windows services and their recovery, automate with Task Scheduler, use event logs with Ge...
Linux vs Unix: the complete guide to commands and distributions
Understand the differences between Linux and Unix, explore distributions (server, desktop, lightw...
Linux administration best practices
Checklist for administering Linux servers: accounts and sudo, SSH, updates, systemd services, sto...
Linux system architecture: kernel, boot and directory tree
Understand how a Linux server works: kernel and user space, the UEFI, GRUB, initramfs and systemd...
Linux server security and hardening
Harden a Linux server: least privilege, updates, secure SSH, firewall, fail2ban, SELinux and AppA...
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...
Users, groups, sudo and permissions on Linux
Manage Linux accounts (useradd, usermod, passwd, chage), groups, sudo and visudo, rwx and octal p...
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...