Skip to content
Visual explainer 2h 30m to learn 4 steps

Logs with journalctl & rsyslog

Filter logs by unit, priority and time and keep the journal across reboots.

By Invicly Tech, , in Linux Administration (RHCSA-style). About 10 minutes to read.

Topic 16 of 42

In short

systemd-journald collects logs from the kernel, services and syslog into a structured, indexed journal. journalctl filters it by unit, priority, time or boot. By default on RHEL the journal may be volatile, so you configure persistent storage to keep logs across reboots, while rsyslog can still write classic files like /var/log/messages.

Explained simply

Every program on a server writes messages about what it is doing: started, connection refused, disk full. These messages are logs, and reading them is how you find out why something broke.

On systemd systems, a service called journald collects nearly all logs in one place: messages from the kernel, from every service's output and from programs using the classic syslog interface. It stores them in a binary journal with extra details, such as which service and which process wrote each line.

journalctl is the tool for reading the journal. Its strength is filtering: show only the sshd service, only errors, only the last hour, or only the boot before the last crash. That turns thousands of lines into the ten that matter.

Many systems also run rsyslog, which writes classic plain-text files under /var/log. Knowing both, and where each distribution puts its files, means you can find logs on any server you are handed.

Press Play on a diagram to walk through it one step at a time.

FlowWhere log messages go
  1. 1
    Sources

    Kernel, service stdout and stderr, syslog calls.

  2. 2
    journald

    Indexes messages with unit, PID and priority.

  3. 3
    Storage

    /run/log/journal (volatile) or /var/log/journal (persistent).

  4. 4
    rsyslog

    Optionally writes /var/log/messages, secure and more.

  5. 5
    Query

    journalctl filters; logrotate trims classic files.

FlowNarrowing a search from everything to the answer
  1. 1
    journalctl

    Every entry, often millions

  2. 2
    -b

    Only this boot

  3. 3
    -u app

    Only one service

  4. 4
    -p warning

    Only warnings and worse

  5. 5
    --since "30 min ago"

    Only around the incident

In depth

Every entry has fields you can filter on

A journal entry is not just a line of text. It is a set of fields. MESSAGE holds the text and PRIORITY the severity. journald adds trusted fields whose names start with an underscore, so programs cannot fake them: _PID, _UID, _COMM (the command name), _EXE, _SYSTEMD_UNIT, _HOSTNAME and _BOOT_ID.

You can filter on any field by writing it as FIELD=value: journalctl _UID=1001 or journalctl _COMM=sshd. Several different fields are combined with AND; the same field given twice means OR. journalctl -F _SYSTEMD_UNIT lists every value a field has, which is a quick way to see which units logged anything.

Shortcuts cover the common cases: -u for a unit, -t for a syslog identifier, -k for kernel messages, and -g (grep) to search the message text with a regular expression.

MapInside one journal entry (journalctl -o verbose)
Journal entry
  • Message
    • MESSAGE=Failed password for root
    • PRIORITY=6
  • Who
    • _PID=1432
    • _UID=0
    • _COMM=sshd
  • Where
    • _SYSTEMD_UNIT=sshd.service
    • _HOSTNAME=web1
  • When
    • __REALTIME_TIMESTAMP
    • _BOOT_ID

Filtering by time, boot and priority

--since and --until accept full dates ("2026-11-10 09:00"), words (today, yesterday) and relative times ("1 hour ago", "-15m"). -b alone means this boot, -b -1 the previous boot and --list-boots shows them all, which needs persistent storage to be useful.

Priorities run from 0 to 7: emerg, alert, crit, err, warning, notice, info and debug. -p err shows err and everything more severe, and a range such as -p warning..err shows just those levels.

Output options help too. -n 50 shows the last 50 lines, -r shows newest first, -f follows new lines live, -e jumps to the end in the pager, and -x adds help text to some messages. -o short-iso prints exact timestamps, -o cat prints only the message, and -o json gives machine-readable output for scripts.

  • journalctl -u nginx -p err --since today
  • journalctl -k -b -1 shows kernel messages from the previous boot
  • journalctl --no-pager | tail is handy inside scripts

Storage, size limits and access

Storage= in /etc/systemd/journald.conf decides where the journal lives. auto, the usual default, keeps it on disk in /var/log/journal if that directory exists, and otherwise only in RAM under /run/log/journal, which is lost at every reboot. persistent always writes to disk and creates the directory, volatile keeps it in RAM only, and none drops logs. Put your settings in a drop-in such as /etc/systemd/journald.conf.d/00-local.conf, then restart systemd-journald.

By default the persistent journal may use up to 10 percent of its file system, capped at 4 GB. Set SystemMaxUse=1G to choose your own limit. journalctl --disk-usage shows the size now, and --vacuum-size=500M or --vacuum-time=2weeks trims old files at once.

Normal users see only their own logs. Members of the systemd-journal group (and adm or wheel on many distributions) can read everything.

rsyslog, classic files and logrotate

rsyslog receives messages from the journal and writes plain text files according to rules of the form facility.priority destination. A facility is the kind of source, such as auth, cron, kern or mail; authpriv.* /var/log/secure sends every authentication message to that file. Rules live in /etc/rsyslog.conf and /etc/rsyslog.d/*.conf.

The file names differ by family. RHEL writes most messages to /var/log/messages and logins to /var/log/secure. Ubuntu uses /var/log/syslog and /var/log/auth.log. Test your rules with logger, for example logger -p local0.notice "test".

Text files would grow forever without logrotate. It runs daily from a systemd timer on current releases, reads /etc/logrotate.conf and /etc/logrotate.d/, and renames, compresses and deletes old files. logrotate -d /etc/logrotate.d/app is a dry run that shows what would happen.

CompareWhere classic logs live
RHEL, Rocky, Alma
  • /var/log/messages: general
  • /var/log/secure: logins and sudo
  • /var/log/cron: scheduled jobs
  • /var/log/maillog: mail
Ubuntu, Debian
  • /var/log/syslog: general
  • /var/log/auth.log: logins and sudo
  • /var/log/kern.log: kernel
  • /var/log/apt/: package history

Learn it in 4 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    Filter journal by unit and priority~40m
  2. 2
    Filter by time and boot~40m
  3. 3
    Make the journal persistent~40m
  4. 4
    Find classic logs in /var/log~40m

Key points

  • journalctl -u NAME shows one unit; -f follows live; -e jumps to the end.
  • -p err shows priority error and worse; --since and --until filter by time.
  • -b shows the current boot and -b -1 the previous one, which needs persistent storage.
  • Set Storage=persistent in journald.conf, or create /var/log/journal, to keep logs across reboots.

Key terms

Tap a card to flip it. 0/5 known

Examples

bash
journalctl -u sshd --since "1 hour ago"
journalctl -p err -b
journalctl -f -u httpd
sudo mkdir -p /var/log/journal
sudo sed -i 's/^#\?Storage=.*/Storage=persistent/' /etc/systemd/journald.conf
sudo systemctl restart systemd-journald
journalctl --list-boots

Filter logs and make the journal persistent.

Make the journal persistent with a size limit

After every reboot, journalctl --list-boots shows only one boot, so you cannot see why the server crashed. Step 1: create a drop-in that sets persistent storage and a 1 GB cap. Step 2: restart journald. Step 3: move the current RAM journal to disk with journalctl --flush. Step 4: check the disk usage, and after the next reboot, confirm that --list-boots shows two entries.

bash
sudo mkdir -p /etc/systemd/journald.conf.d
printf '[Journal]\nStorage=persistent\nSystemMaxUse=1G\n' \
  | sudo tee /etc/systemd/journald.conf.d/00-persistent.conf
sudo systemctl restart systemd-journald
sudo journalctl --flush
ls /var/log/journal/
journalctl --disk-usage
journalctl --list-boots

Who tried to log in, and from where?

You suspect someone is guessing SSH passwords. Step 1: show today's failed password messages from the SSH service (the unit is sshd on RHEL and ssh on Ubuntu). Step 2: count attempts per source IP. Step 3: see which user names were tried. Step 4: check whether any login succeeded. Filtering by unit is more reliable than grepping text files, because it cannot pick up lines from other programs.

bash
U=sshd    # Ubuntu: U=ssh
journalctl -u $U --since today -g 'Failed password' -o cat | head
journalctl -u $U --since today -g 'Failed password' -o cat \
  | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn | head
journalctl -u $U --since today -g 'Failed password' -o cat \
  | grep -oE 'for (invalid user )?[^ ]+' | sort | uniq -c | sort -rn | head
journalctl -u $U --since today -g 'Accepted' -o short-iso

Quick reference

  • journalctl -u NAME -f follows one service live
  • journalctl -p err -b shows errors and worse from this boot
  • journalctl -b -1 -e jumps to the end of the previous boot's log
  • journalctl _UID=1001 or _COMM=sshd filters on any journal field
  • journalctl -g 'regex' searches message text without a separate grep
  • mkdir /var/log/journal or Storage=persistent keeps logs across reboots
  • journalctl --vacuum-size=500M trims the journal right away
  • logger -p user.err "test" writes a test message you can then find

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which command shows warnings and more severe messages for the nginx unit since midnight?

Question 2

2Storage=auto is set and /var/log/journal does not exist. Where is the journal kept?

Question 3

3On Ubuntu, where do you find classic text logs of SSH logins and sudo use?

Question 4

4Why are journal fields like _PID and _SYSTEMD_UNIT considered trustworthy?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Show the last 20 log lines of the sshd service with exact ISO timestamps, then follow it live while you log in from another terminal.

  2. Exercise 2medium

    Send a test message with priority err and tag myapp, then find it in the journal using its tag and priority only.

  3. Exercise 3hard

    Write an rsyslog rule that copies every message from the myapp tag into /var/log/myapp.log, and a logrotate config that keeps 7 compressed daily copies. Test both.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Is /var/log/messages gone on systems with journald?
No. On RHEL, rsyslog still writes it from the journal. The journal is the main store, and the text files are a copy for tools and habits that expect them.
Can I read journal files from another machine or a rescue disk?
Yes. Copy the files from /var/log/journal or mount the disk, then run journalctl -D /path/to/journal or --file to read them.
Why does journalctl show nothing for my user?
Normal users only see their own messages. Use sudo, or add the user to the systemd-journal group (adm on Ubuntu also works).
How long does the journal keep logs?
Until it reaches its size limit, by default up to 10 percent of the file system and at most 4 GB, then the oldest files are removed. MaxRetentionSec= sets a time limit if you need one.

Go deeper

ShareXLinkedInWhatsApp