brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Guide: find out why a Linux service failed, with journalctl

Guide: find out why a Linux service failed, with journalctl

Guide linux

12 steps 13 min read

A service falls over at night, and by morning all you have is a hunch. The answer is nearly always in the systemd journal, and journalctl can find it in a minute once you know a handful of flags. This guide walks through them one at a time, with terminal output, and ends with a two-page cheat sheet you can print.

Time
13 min
Steps
12
Updated
27 Nov 2026

You will learn

  • Read the journal without drowning in…
  • Show only one service
  • Ask for a time range
  • Filter by how bad it is
  • Search the text of the messages

What you get, and what you need

By the end you can open a server’s log and find the three lines that explain a crash in about a minute. You need a Linux machine that runs systemd, which covers Ubuntu, Debian, Fedora and most of the distros people put on a small server. Everything here was written against systemd 255 on Ubuntu 24.04. Older versions miss a few flags, and I say so where it matters.

Unraid is the exception. It keeps its log in /var/log/syslog and has no journal, so this guide is for your Linux VMs, your Raspberry Pi and any other box you run next to it. If you only care about Unraid, the syslog tips on this site are the better start.

The log lines in the screenshots are demo lines. I wrote them into the journal with systemd-cat on a throwaway machine, so the identifiers demo-backup and demo-sshd will not exist on yours. The commands and the output format are the real thing. Swap in a unit name from your own server, such as ssh or docker, and you get the same kind of output.

The journal is a database of log entries with fields: the service, the time, the priority, the text. Each flag you add is one more condition on those fields, and what you see are the entries that match all of them.

Step 1 of 12: Read the journal without drowning in it

Run journalctl on its own and you get every entry since the journal began, oldest first, in a pager. On a server that has been up for months that is a wall of text, and the part you want is at the very bottom. You can press G to jump there, but there are better ways to start.

journalctl -n 50
journalctl -e
journalctl -r

-n 50 prints the last 50 entries and stops. -e opens the pager already at the end, and it also limits the output to the last 1000 lines of the current boot, so the pager never has to hold the whole history. -r reverses the order so the newest entry is on top. I use -n when I want a quick look and -e when I expect to scroll.

When the output goes into another command, add --no-pager. Without it journalctl waits for you at the end of the screen, which is no good in a script or behind a pipe. Inside the pager the arrow keys scroll, / searches and q leaves. Lines that run off the right edge of your terminal are cut off, and less -S after a pipe lets you scroll sideways instead of wrapping them.

Step 2 of 12: Show only one service

Most of the time I want one thing: what did this service say? -u takes a unit name, and the .service suffix is optional.

journalctl -u ssh
journalctl -u 'docker*'
journalctl -u nginx -u php8.3-fpm

The second command uses a pattern, so it matches every unit whose name starts with docker, including docker.socket. The third lists two units, and their entries come out interleaved in time order. That is the quickest way to see a reverse proxy and the app behind it complain in the same minute. On Ubuntu the SSH unit is called ssh, on Fedora it is sshd, so check the name with systemctl list-units --type=service if the first try prints nothing.

Not every program is a unit. A script started from cron, or a tool that writes to the journal under its own name, shows up under a syslog identifier. -t filters on that. It is also how the demo entries in the screenshots are found.

journalctl -t CRON
journalctl -t demo-backup

Two more shortcuts belong here. -k shows kernel messages only, the same text you see from dmesg, and it implies the current boot. --user-unit does what -u does for services in your own user session. Run journalctl -F _SYSTEMD_UNIT if you want to see which unit names your journal actually knows about.

Step 3 of 12: Ask for a time range

A long-running service writes a lot, and most of it is old news. --since and --until cut the journal down to the window you care about. They accept a full date and time, a bare date, the words yesterday, today and now, and relative times like "1 hour ago".

journalctl -u ssh --since "1 hour ago"
journalctl --since yesterday --until today
journalctl --since "2026-11-26 18:00" --until "2026-11-26 18:30"

The third form is the one I would reach for after an alarm, because the alarm gives me a time and I want the half hour around it. If the clock on the machine is in UTC and your own is in Leiden time, remember that you are comparing across a one or two hour difference. --utc prints the journal in UTC so the two stop fighting.

Boots are a time range too. -b means the current boot, and -b -1 means the one before it. That second one is what you need after a machine froze and you rebooted it by hand, because the last minutes before the freeze are in the previous boot. journalctl --list-boots shows the numbering, the boot IDs and when each boot started and ended.

journalctl --list-boots
journalctl -b -1 -e

There is a catch, and it trips up almost everyone once: on many installs the journal lives only in memory and disappears at reboot, so -b -1 finds nothing. I come back to that further down, because it is a two-line fix.

Step 4 of 12: Filter by how bad it is

Every journal entry carries a priority from 0 to 7. They are the classic syslog levels: emerg, alert, crit, err, warning, notice, info and debug, in that order. -p takes a name or a number, and it shows that level and everything more serious.

journalctl -b -p err
journalctl -b -p warning
journalctl -b -p 3..4

-p err prints errors and worse. -p warning adds warnings. A range like 3..4 or warning..err gives exactly those levels and nothing else, which is handy when the errors are already known and you want to see what came just before them. Services pick their own priorities, so treat the level as a hint. A well-behaved service logs real failures as err, and a sloppy one logs everything as info.

My habit on a machine I do not know: run journalctl -b -p err first. If it prints a handful of lines, I read them. If it prints thousands, one service is in a loop, and I spot it by the name that repeats.

Terminal output of journalctl filtered by identifier, then by warning priority
Sample entries: all of demo-backup first, then only warnings and errors

Step 5 of 12: Search the text of the messages

-g filters on the message itself with a regular expression. It uses PCRE syntax, so most things you know from grep -P work. A pattern that is all lowercase matches regardless of case. As soon as you include a capital letter the match becomes case sensitive, and --case-sensitive lets you set it yourself.

journalctl -u ssh --since today -g "failed password"
journalctl -b -g "out of memory|oom"

The first command is a quick way to see who knocks on your SSH port. Failed password attempts from addresses you do not know are normal on anything reachable from the internet, and a long run of them from one address is the thing to act on, for example with a firewall rule or by turning off password logins. The second one lists out-of-memory kills of this boot, which explains a container that vanished without a message of its own.

Combining flags is where journalctl pays off. -u, -b, -p and -g all apply at once, in any order. When a command returns too much, add another flag. When it returns nothing, remove the newest one and see which condition cut everything away.

Terminal output of journalctl with grep, the boot list and disk usage

A grep match, the boot list and the disk usage of the journal

Step 6 of 12: Follow a service while you restart it

-f keeps the command running and prints each new entry as it arrives, like tail -f. Stop it with Ctrl-C. Because it starts with only the last few lines, you can add -n 100 to start with more context.

journalctl -u docker -f -n 100

The way I use it: open two terminals, follow the unit in one, and restart or reconfigure it in the other. The line that appears right after you press Enter is usually the reason, and you did not have to hunt for it in a file. If the service is a container, remember that its own output goes through Docker and not through its host unit, and use docker logs -f for that side.

Step 7 of 12: Change how the entries look

The default format is the classic syslog line: date, host name, identifier with the process ID, and the message. -o changes it, and a few formats are worth knowing.

journalctl -u ssh -o short-iso
journalctl -u ssh -o cat
journalctl -u ssh -n 1 -o json-pretty

short-iso prints timestamps in ISO 8601 with the UTC offset, which is much easier to compare with monitoring graphs. cat prints only the message text and nothing else, and that is the one to pipe into other tools. json-pretty prints one entry with every field, and it is the best way to learn what you can filter on. The names in that output, such as PRIORITY, SYSLOG_IDENTIFIER and _PID, work as matches on the command line: journalctl _PID=1234 shows everything one process wrote.

Two flags help you explore. journalctl -N lists all field names in your journal, and journalctl -F FIELD lists every value one field has taken. Run journalctl -F PRIORITY and you see which levels your services actually use. Add -x to a command and some entries get a short explanation underneath, taken from the message catalog. Not every entry has one, but the ones that do usually describe a boot or a failed unit in plain language.

One journal entry printed as json-pretty with every field

One entry in json-pretty format: every field you can filter on

Step 8 of 12: Keep the logs after a reboot

Here is the fix I promised. The setting that decides this is Storage= in /etc/systemd/journald.conf. With auto, which is the usual default, journald writes to disk only if the directory /var/log/journal exists, and keeps the journal in memory otherwise. Some distributions create that directory, and others do not. If your --list-boots shows a single boot, you are in the second group.

sudo mkdir -p /var/log/journal
sudo systemctl restart systemd-journald
sudo journalctl --flush
journalctl --list-boots

After the restart journald writes to disk, and --flush asks it to move what it still holds in memory over to /var/log/journal. From the next reboot on, -b -1 has something to show. If you would rather not depend on a directory, set Storage=persistent in the config file and restart journald. Do this before the day you need the old logs.

Step 9 of 12: Stop the journal from filling the disk

A journal on disk grows until it hits a limit, and the default limit is generous. Check where you stand first.

journalctl --disk-usage

To trim it by hand, journalctl can delete archived files. --vacuum-size=500M removes the oldest archived files until the total is under 500 megabytes. --vacuum-time=2weeks removes archived files older than two weeks, and --vacuum-files=5 keeps five. Only archived files go, never the one journald is writing to, so the result can be somewhat above the number you asked for.

sudo journalctl --vacuum-size=500M
sudo journalctl --vacuum-time=2weeks

For a permanent limit, put a drop-in file in /etc/systemd/journald.conf.d/ instead of editing the main file, so an update does not overwrite it.

[Journal]
SystemMaxUse=500M
MaxRetentionSec=1month

SystemMaxUse= caps the size on disk. MaxRetentionSec= also drops entries by age, and it is off by default. Restart systemd-journald after a change. I like having both on a small server. There is a Dutch angle too: log lines often hold IP addresses, and under the GDPR an IP address counts as personal data. A journal that keeps everything forever is a pile of personal data you never decided to keep, so an age limit is a good habit even on a home server.

Step 10 of 12: Check who is allowed to read it

If journalctl shows only your own entries, or prints a hint about missing permissions, the journal is fine and your account is the problem. A normal user sees the entries of that user. Root, and members of the groups adm, systemd-journal and wheel, can read everything. On Ubuntu and Debian the account you created at install time is usually in adm already. On another distribution, add yourself once:

sudo usermod -aG systemd-journal $USER

Log out and back in so the new group applies. Adding a person to this group gives them read access to every log on the machine, including entries from other users and from services that print tokens or paths by mistake. For a shared server I would grant it deliberately and not by default.

Step 11 of 12: Copy the recipes I would keep

These are the commands I would put in a notes file. Each one is a question you will ask sooner or later.

# why did a service fail on this boot?
journalctl -u nginx -b -p err

# follow a service live, with some context
journalctl -u docker -f -n 100

# everything noisy from the last hour
journalctl --since "1 hour ago" -p warning

# kernel errors from before the last reboot
journalctl -k -b -1 -p err

# one entry with all its fields
journalctl -u ssh -n 1 -o json-pretty

The same list, with the disk-space commands and the level table, is on a two-page PDF, so you can print it and stick it next to the monitor.

Step 12 of 12: Where to go from here

Start with -u, -b and -p, add -g and --since when you need them, and look up the rest when a problem asks for it. This site has a collection of short journalctl tips, one flag at a time, and they sit below this section. The links below shows that page.

If you want the long version of every option, the manual page is complete and readable. The links are in the further reading list. The page for journald.conf explains every storage and size setting in that file, and I would read it once before changing limits on a machine that matters.

Further reading

Link