What you will learn in this TP
- Manage packages and services
- Write a hardened systemd unit
- Schedule with a timer
Introduction #
What you will learn in this section
- Manage packages and services
- Write a hardened systemd unit
- Schedule with a timer
Context. A small internal application is started by hand in a terminal and stops at every logout. You turn it into a proper, supervised and hardened service.
Prerequisites: a disposable Ubuntu 24.04 virtual machine (Multipass, Vagrant or cloud) with a sudo account · Estimated time: 45 min
A service that starts at boot, restarts on its own and is checked every minute.Hands-on #
Guided steps, with their solution.
1. Install and manage nginx
Why? A distribution package already ships its systemd unit: learn the commands on a simple case.
Update the index, install nginx, check it is active and enabled at boot, and test it with curl.2. Prepare the application
Why? The application runs under a dedicated service account, never root.
Create theappaccount (if missing) and a static site in/srv/app/wwwserved bypython3 -m http.serveron port 8080.3. Write the unit
Why? systemd starts the service at boot, restarts it on crash and isolates it from the rest of the system.
Create/etc/systemd/system/app.servicewithRestart=on-failureand hardening options, reload systemd, enable and start the service.4. Test automatic restart
Why? Verify crash behaviour instead of assuming it.
Kill the main process with SIGKILL, see a new PID appear, then find the event in the journal.5. Override the unit
Why? A drop-in override changes a service without editing its file, and survives updates.
Limit the service memory to 200 MB and CPU to 50% with an override, then check the applied values and the security score.6. Schedule a check with a timer
Why? A systemd timer logs every run and catches up missed ones, unlike cron.
Create ahealthcheckservice querying/healthand a timer running it every minute. Stop the application and watch the failure in the journal.
Difficulty level : ●●○○○ (2/5)
My 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
Packages, systemd services, logs and scheduled tasks
Install and update software with apt and dnf, manage services with systemctl, write a systemd uni...
Linux vs Unix: the complete guide to commands and distributions
Understand the differences between Linux and Unix, explore distributions (server, desktop, lightw...
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 administration best practices
Checklist for administering Linux servers: accounts and sudo, SSH, updates, systemd services, sto...
Users, groups, sudo and permissions on Linux
Manage Linux accounts (useradd, usermod, passwd, chage), groups, sudo and visudo, rwx and octal p...
Linux server security and hardening
Harden a Linux server: least privilege, updates, secure SSH, firewall, fail2ban, SELinux and AppA...
HAProxy cheat sheet: the essential commands
A practical guide gathering all the essential commands to install, manage, test and debug HAProxy...
The Bash shell and files: navigation, redirections, pipes and text processing
Master the Linux command line: paths, file handling, wildcards, redirections, pipes, searching wi...
Storage on Linux: disks, partitions, file systems and LVM
Administer Linux storage: lsblk and blkid, GPT partitioning, ext4 and XFS, mounting and /etc/fsta...