Chapter 1 · Lesson 9 of 19
Server basics

Read logs with journalctl

journalctl reads the logs that systemd collects from the system and from every service, in one searchable place.

By the end you will

Read, follow and filter system and service logs with journalctl.

Time
12 min
Level
Beginner
Check
4 questions
You need
  • A systemd Linux server with sudo access

A service stops answering. To read its logs on a systemd server, run sudo journalctl -u servicename -n 50. You could guess, or you could read what it said just before it failed: the error, the exit code, the line that tells you which file it could not open. On a systemd server that history is in the journal. Learning a handful of journalctl options turns a vague failure into a specific message.

How it works#

systemd starts and supervises services. It captures everything a service prints to its standard output and standard error, plus messages sent through the system log interface, and stores them in a binary journal. The journal records the time, the unit (service) name, a priority level and the message. Because it is indexed, journalctl can filter fast by unit, time, boot or priority.

Messages carry a priority from emerg and alert through crit, err, warning, notice and info to debug. Filtering with -p err shows err and anything more severe.

The journal may be volatile, kept in memory under /run/log/journal and lost at reboot, or persistent, kept in /var/log/journal. On Ubuntu it is normally persistent. Its size is capped by system settings, so very old entries are removed automatically.

Programs that write their own files, such as nginx, still write to /var/log/nginx/. The journal covers systemd services and the system itself, and you read other logs with tail and less.

A worked example: your app service demo fails after a deploy. You run sudo journalctl -u demo -n 30 --no-pager. The last lines say it could not open a config file. You fix the path, run sudo systemctl restart demo, then sudo journalctl -u demo -f and watch it start cleanly. You read, fix, restart and watch, using the same tool each time.

Step 1: Read recent logs#

bash
sudo journalctl -n 50

-n 50 shows the last 50 lines. Without it you get every stored entry, oldest first, in a pager.

What you should see: lines that start with a date and time, the host name, the program name with its process ID and a message.

Step 2: Show logs for one service#

bash
sudo journalctl -u ssh

-u filters by unit name. On Ubuntu the SSH service is ssh. On other systems it may be sshd. Add -e to jump to the end.

What you should see: only lines from that service, such as login messages. Use -r to show the newest first.

Step 3: Follow logs live#

bash
sudo journalctl -u ssh -f

New lines appear as they happen. Press Ctrl+C to stop.

What you should see: the last few lines, then the command waits. Log in from another terminal and a new line appears.

Step 4: Filter by time and level#

bash
sudo journalctl --since "1 hour ago"
sudo journalctl -p err -b
sudo journalctl -u ssh --since "2026-11-27 09:00" --until "2026-11-27 10:00"

--since and --until limit the time range. -p err shows only errors and worse, and -b limits the output to the current boot.

What you should see: a shorter list, or -- No entries -- if nothing matches.

Step 5: Check how much space logs use#

bash
journalctl --disk-usage

What you should see: a line such as Archived and active journals take up followed by a size. Logs can grow over time (the same worry as in check disk, memory and CPU usage). Trimming them is a deliberate step, so read the journalctl manual before you run --vacuum-size or --vacuum-time, which delete old entries.

Check it worked#

After step 1 you should see lines that start with a date, the host name, the program name and a message. After step 3 the command should wait and print new lines as they arrive, for example when you log in again with SSH. For a plain text version that works in scripts, add --no-pager and -o short-iso, which prints ISO timestamps.

Edge cases and gotchas#

  • Times are shown in the server’s time zone. If the server runs UTC and you think in local time, your --since windows will look off. Check timedatectl. Add --utc to be explicit.
  • The journal can be empty after a reboot. If the journal is only in memory, the logs before the reboot are gone. Create /var/log/journal and restart systemd-journald, or set Storage=persistent in the journald config, if you want to keep them.
  • Lines may be cut off. The pager does not wrap long lines. Use --no-pager or press the right arrow, and add -o cat to print only the message.
  • A service’s own file logs are separate. If a program logs to /var/log/app.log, journalctl will not show those lines unless the service also writes to the console.
  • Docker container logs are not in the journal by default. (See read container logs.) Use docker logs or docker compose logs. Docker’s own daemon messages are under -u docker.
  • Kernel messages have their own view. journalctl -k shows the kernel ring buffer, which is where out-of-memory kills and disk errors appear.
  • -u matches the unit name, not the program. The service for Docker is docker, and for SSH on Ubuntu it is ssh. Check with systemctl list-units --type=service.
  • Permissions hide other users logs. A normal user sees only its own entries unless in the systemd-journal group.

Troubleshooting#

SymptomLikely causeFix
No journal files were found.Journal not stored on disk or you lack accessTry sudo, or check the persistent storage setting
-- No entries --Filters are too narrowWiden the time range or check the unit name
systemctl status nginx says Unit nginx.service could not be found. and journalctl -u nginx shows no entriesWrong service name or not installedList with systemctl list-units --type=service
Hint that you are not seeing all messagesYour user is not in the right groupUse sudo or add yourself to systemd-journal
Output ends with lines 1-23 and waitsYou are in the pagerPress q
Logs stop at an old dateThe journal was rotated or vacuumedCheck journalctl --disk-usage and the size limit
Output too wide to readLong lines in the pagerAdd --no-pager or -o cat
Cannot find old logs after rebootJournal is volatileMake it persistent, see the gotchas above

Real-world scenario#

Nina deploys an update and the site returns errors. The service is called webapp. She runs sudo systemctl status webapp and sees activating (auto-restart), so it keeps crashing. She runs sudo journalctl -u webapp -n 40 --no-pager and finds Error: EADDRINUSE, which means another process holds the port.

She checks with sudo ss -ltnp and finds an old copy of the app still running. She stops it, restarts the service, and journalctl -u webapp -f shows a clean start.

Without the journal she would have guessed. With it she read the answer in the first screen.

Quick reference#

TaskCommand
Last 50 linessudo journalctl -n 50
One servicesudo journalctl -u ssh
Follow livesudo journalctl -u ssh -f
Since a timesudo journalctl --since "1 hour ago"
Errors this bootsudo journalctl -p err -b
Previous bootsudo journalctl -b -1
Kernel messagessudo journalctl -k
Space usedjournalctl --disk-usage

Security and safety notes#

  • --vacuum-size and --vacuum-time delete log history for good. Do not run them while you are still investigating a problem.
  • Logs can contain passwords, tokens or personal data. Check before you paste them into a public forum.

Next#

Run a service with systemd.

Check what you learned4 questions
1Which command follows the SSH service log live?
2What does journalctl -p err -b show?
3Why be careful with --vacuum-size?
4A service crashed and the server rebooted. How do you read the logs from before the reboot?

Frequently asked questions

Why do I get no entries or a permission message?

Normal users may only see their own logs. Use sudo, or add your user to the systemd-journal group.

How do I leave the log view?

Press q. The output opens in a pager, so you can also scroll with the arrow keys and search with a slash.

Do logs survive a reboot?

Only if the journal is stored on disk. On some systems it is kept in memory and lost at reboot. Check for the /var/log/journal folder, and ask for the previous boot with journalctl -b -1.

Where are the logs of my Docker containers?

Docker keeps its own container logs, read with docker logs. The journal shows the Docker service itself. See the container logs lesson.

Sources

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios