Read your logs with journalctl
A service refuses to start and the machine says nothing? Quite the opposite: it wrote everything down. Let's learn to read its logs with journalctl and find the cause in two minutes.
- Course
- Tutorial 14 of 35
- Time
- 20 min to read
- Tested with
- Commands: tested on Debian 13.7 (systemd 257)
What you will be able to do
- Read the last lines of the log and understand one line.
- Filter by service, by time and by severity.
- Follow the log live.
- Find out why a service won't start.
Before you start: Updates and packages with apt.
Contents
How do you read the logs of a Debian server with journalctl? When a program misbehaves, the answer is almost always in its log, not on your screen. We will learn five moves: read the last lines, pick a service, pick a time range, filter by severity and follow live. That is already enough to diagnose your first breakdowns. You will use sudo and apt, which are covered in Updates and packages with apt.
What is a log
A log is the notebook where the server writes down, line after line, what each program tells it: a successful login, a failure, an error. On Debian, a single program keeps this notebook for all the others, and the journalctl command reads it. No need to dig through dozens of files, everything is in one place.
One rule first. The full log is reserved for the administrator, so every command in this article starts with sudo. Without it, alice only sees her own lines, and the command says so at the top of its answer: Hint: You are currently not seeing messages from other users and the system. Now let's see what this notebook looks like.
1Read the last lines
To read the end of the log, add -n followed by the number of lines you want. Let's ask for the last five.
sudo journalctl -n 5Five lines appear, the newest at the bottom. If the answer is longer than your screen, a pager opens: the arrow keys scroll and q closes it. Each line reads from left to right, like this one, taken from one of alice's logins:
Nov 05 01:23:25 mon-serveur sshd-session[3840]: Accepted password for alice from 192.0.2.50 port 44846 ssh2- Nov 05 01:23:25: the date and time of the event.
- mon-serveur: the name of the machine that wrote the line.
- sshd-session[3840]: the program that produced the message, then its process number in square brackets. That number changes every time the program starts.
- Accepted password for alice from 192.0.2.50…: the message itself. Here, alice logged in with her password from the address
192.0.2.50. With a key, you will readAccepted publickey.
With the date, the program and the message, you know who did what and when. But the log mixes all the programs, and the line you want drowns fast. Time to learn how to sort.
2Keep only one service
The -u option, short for unit, keeps only the lines of a single service, meaning a program that runs all the time. Let's keep SSH, the service that receives your logins, and look for successful logins with grep, which keeps only the lines containing a word.
sudo journalctl -u ssh | grep Accepted | tail -2Nov 05 01:23:25 mon-serveur sshd-session[3840]: Accepted password for alice from 192.0.2.50 port 44846 ssh2
Nov 05 01:24:02 mon-serveur sshd-session[4008]: Accepted password for alice from 192.0.2.50 port 55284 ssh2Your lines will show other dates and other addresses. Notice the name given to -u: ssh, not sshd. On Debian, the service is called ssh. With sshd, the answer is -- No entries --, which wrongly makes you think the log is empty.
Find the exact name of a service
The systemctl list-units --type=service command lists the names of the running services.
A service's log can hold thousands of lines. Combined with -n, -u shows only the end: sudo journalctl -u ssh -n 20. Next, choose the time range to read.
3Pick the time range and the severity
Three options shrink the log down to what matters. Each one combines with -u and with the others:
--sinceand--untilset the time range:--since "1 hour ago",--since yesterdayor--since "2026-11-05 01:00:00"(an exact date).-bkeeps the lines since the machine last started, called the boot.-b -1shows the previous boot, handy after a crash followed by a restart.-pkeeps the lines of a given severity, from 0 (the most serious) to 7 (the chattiest).
Every log message carries a severity level. Here they are, from the most serious to the least:
| Level | Name | Meaning |
|---|---|---|
| 0 | emerg | the machine is unusable |
| 1 | alert | act right now |
| 2 | crit | serious failure |
| 3 | err | an error |
| 4 | warning | a warning |
| 5 to 7 | notice, info, debug | plain information |
The -p err option keeps that level and every more serious one. Here are the errors of the last hour:
sudo journalctl -p err --since "1 hour ago"On a healthy server the answer is short, even -- No entries --: no error in that period. It's the right first reflex when something is off: -p err first, the rest of the log afterwards. And what if you'd rather watch lines arrive than dig for them afterwards?
4Follow the log live
The -f option, short for follow, keeps the command open and prints each new line as soon as it is written. It is like watching the notebook while someone writes in it. Let's follow SSH, then log in from a second terminal.
sudo journalctl -f -u sshThe command doesn't give your prompt back: it waits. Open a second SSH connection from your computer, and lines appear, including the Accepted for your arrival. Press Ctrl and C together to stop. It's ideal for restarting a service in one terminal and watching its log react in the other. On to a real case: what do you do when a service won't start?
5Find out why a service won't start
When a service fails, two commands almost always give the cause: systemctl status to see the state, then journalctl -u to read the details. To practice without breaking anything, let's create a fake service, demo, whose program doesn't exist. The file below describes the service to systemd, the program that starts and watches every service on Debian.
sudo tee /etc/systemd/system/demo.service > /dev/null <<'EOF'
[Service]
ExecStart=/usr/local/bin/demo-introuvable
EOF
sudo systemctl daemon-reload
sudo systemctl start demoThe daemon-reload command tells systemd to reread its files, so it finds ours. The start prints nothing, and yet everything failed. Let's ask for the state.
sudo systemctl status demo Loaded: loaded (/etc/systemd/system/demo.service; static)
Active: failed (Result: exit-code) since Thu 2026-11-05 01:23:41 UTC; 10ms ago
Duration: 40ms
Invocation: b96e3fdcef2f4ecf9b7764bbe3dea061
Process: 3921 ExecStart=/usr/local/bin/demo-introuvable (code=exited, status=203/EXEC)
Main PID: 3921 (code=exited, status=203/EXEC)
Mem peak: 1.7M
CPU: 7ms
Nov 05 01:23:41 mon-serveur systemd[1]: Started demo.service.
Nov 05 01:23:41 mon-serveur (rouvable)[3921]: demo.service: Unable to locate executable '/usr/local/bin/demo-introuvable': No such file or directory
Nov 05 01:23:41 mon-serveur (rouvable)[3921]: demo.service: Failed at step EXEC spawning /usr/local/bin/demo-introuvable: No such file or directory
Nov 05 01:23:41 mon-serveur systemd[1]: demo.service: Main process exited, code=exited, status=203/EXEC
Nov 05 01:23:41 mon-serveur systemd[1]: demo.service: Failed with result 'exit-code'.Your dates and numbers will be your own. Read only three things: Loaded says the service is known, Active: failed says it fell over, and the dated lines at the bottom are an excerpt of the log. Among them, Unable to locate executable … No such file or directory gives the cause in plain words: the program doesn't exist at that path. The rest is optional. Invocation is the unique ID of this run, Process and Main PID describe the program that failed (status=203/EXEC means it couldn't be launched), and Duration, Mem peak and CPU give its lifetime, its peak memory and its computing time. As for (rouvable), it is the program's temporary name, cut short by the system: it is the end of demo-introuvable. To read the whole log of the service, not just those lines:
sudo journalctl -u demo --no-pagerNov 05 01:23:41 mon-serveur systemd[1]: Started demo.service.
Nov 05 01:23:41 mon-serveur (rouvable)[3921]: demo.service: Unable to locate executable '/usr/local/bin/demo-introuvable': No such file or directory
Nov 05 01:23:41 mon-serveur (rouvable)[3921]: demo.service: Failed at step EXEC spawning /usr/local/bin/demo-introuvable: No such file or directory
Nov 05 01:23:41 mon-serveur systemd[1]: demo.service: Main process exited, code=exited, status=203/EXEC
Nov 05 01:23:41 mon-serveur systemd[1]: demo.service: Failed with result 'exit-code'.The --no-pager option prints everything at once instead of opening the pager. The habit to keep has three steps: status for the state, journalctl -u for the cause, then fix it and start again. To clean up, let's delete the fake service. reset-failed wipes the "failed" mark that systemd keeps in memory.
sudo rm /etc/systemd/system/demo.service
sudo systemctl daemon-reload
sudo systemctl reset-failed demoGet extra explanations: -xe
Add -x and journalctl slips short explanatory paragraphs under some lines. Add -e to jump straight to the end: sudo journalctl -xeu demo. Error messages from systemctl often suggest exactly that.
You can now find the cause of a breakdown. One last, quieter concern: a log that grows forever.
6Keep the logs a reasonable size
The log grows as long as the server runs, but Debian puts a cap on it: by default it takes at most 10% of the disk, and never more than 4 GB. Check its current size with --disk-usage.
sudo journalctl --disk-usageArchived and active journals take up 16M in the file system.Your figure will be different. If the log takes too much room, --vacuum-size deletes the oldest lines down to the size you ask for, and --vacuum-time deletes everything older than a given age.
sudo journalctl --vacuum-size=200MThe command answers Vacuuming done, freed …, with the space it freed. It acts only once. To set a permanent limit, write it in a small settings file.
Set a permanent limit: SystemMaxUse
This file caps the log at 200 MB. It lives in a folder of your own, which updates leave alone.
sudo mkdir -p /etc/systemd/journald.conf.d
sudo tee /etc/systemd/journald.conf.d/taille.conf > /dev/null <<'EOF'
[Journal]
SystemMaxUse=200M
EOF
sudo systemctl restart systemd-journaldIf it fails
Four messages come back most often:
Hint: You are currently not seeing messages from other users and the system.You forgotsudo. Run the same command again withsudoin front.-- No entries --No line matches. Check the service name (ssh, notsshd) and widen the time range, for example--since yesterday.No journal boot entry found for the specified boot (-1).There is no previous boot, because the machine hasn't restarted since its installation. That's normal.- The command seems frozen. You are in the pager or in
-f. Typeqfor the pager,CtrlandCfor-f.
What's next
You can now ask the server what it did and why something failed. But the log only tells the past: if the disk dies or you delete a file by mistake, it gives nothing back. The next article, Your first backup with rsync, puts your data out of harm's way with a first backup.