SECURITY ENGINEERING · PART 1 · LINUX AND WINDOWS, FROM THE INSIDE · LINUX · 11 OF 229

Linux Security Logs: auth.log, journald, auditd

Where Linux records who did what, read as a defender: the auth log for logins and sudo, journald and the system logs, the Linux audit framework (auditd) for fine-grained rules on commands and file access, which events actually matter for detection, and why logs must be shipped off the box before an attacker can wipe them.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • auth.log and journald
  • auditd rules for exec and file access
  • ship off-box
  • alert on the few events that matter

Notes

The auth log

The first place a defender looks is the authentication log, called auth dot log on Debian and Ubuntu, or secure on Red Hat systems. It records SSH logins, both accepted and failed, sudo and su use, and account changes. A burst of failed passwords is a brute-force attempt. A successful login from an unexpected address, followed by sudo to root, is the shape of a break-in. Knowing these few lines by sight makes you fast at triage.

auth.log (Debian/Ubuntu)
sshd: Accepted publickey for
  deploy from 10.0.0.9
sshd: Failed password for
  invalid user admin ...
sudo: deploy : COMMAND=...
su: session opened for root
(RHEL: /var/log/secure)

journald

On modern systems, systemd's journal, read with journalctl, collects logs from services, the kernel and the system. You can filter by service, by user, by time or by priority, which makes it the fastest way to reconstruct what happened around an event. One setting matters for security: make the journal persistent, so it survives a reboot. By default some systems keep it only in memory, and a reboot, which an attacker might trigger, erases the evidence.

Reading the journal
journalctl -u ssh        a unit
journalctl _UID=1000     a user
journalctl --since "1 hour ago"
journalctl -p err        errors
journalctl -k            kernel
persist across reboots:
  Storage=persistent in
  journald.conf

auditd

For precise detection you use the Linux audit framework, auditd. It works in the kernel and is driven by rules. You can watch a file, so any write to the password file is recorded with who did it. You can watch a system call, so every command execution is logged. Each rule carries a key so you can search for it later with ausearch. This is how you catch a service account spawning a shell, or a sensitive config being read, which ordinary logs miss.

The Linux audit framework
  • kernel-level, rule-driven
  • watch a file: -w /etc/passwd -p wa -k passwd
  • watch a syscall/command: -a always,exit -F arch=b64 -S execve -k exec
  • logs to /var/log/audit/audit.log
  • ausearch -k passwd to query

Rules worth having

A good starter policy watches the things attackers touch: writes to system directories, reads of the shadow file, changes to the sudoers and SSH configuration, new SUID files, kernel module loads, and use of su, sudo and passwd. Watching command execution by service accounts is especially powerful, because a web account running bash is almost always bad. Start from a published ruleset, such as the ones aligned to the CIS benchmarks, and tune out the noise for your systems.

High-value audit rules
  • writes to /etc, /bin, /sbin
  • reads of /etc/shadow
  • changes to sudoers and SSH config
  • new SUID files, module loads
  • use of su, sudo, passwd
  • execve by service accounts
  • base it on a CIS/Auditd ruleset, then tune

Ship it off-box

Here is the rule that matters most. Logs stored only on the machine are evidence the attacker can edit or delete, and clearing them is one of the first things they do. So ship logs off the box in near real time, with a forwarder like rsyslog, Fluent Bit or an agent, into a central system. Now an attacker cannot erase what already left, and you can search across every host at once. Part thirteen builds that central pipeline; this episode is why it exists.

Centralise the logs
  • forward to a central collector: rsyslog, journald remote, Fluent Bit, the Elastic/Wazuh agent
  • then to a SIEM (Part 13)
  • benefits: an attacker on the box cannot erase them; you can search across hosts

Anti-tampering

Assume the attacker will try to cover their tracks, so protect the record. The main defense is forwarding, because they cannot reach what already left. On the box, you can make audit logs append-only and lock the audit configuration. And you alert on tampering itself: the logging service being stopped, the journal being cleared, the auth log suddenly truncated. A gap in the logs where there should be activity is not nothing. It is a signal worth investigating on its own.

Protect the record
  • forward before they can delete
  • make audit logs append-only (chattr +a) and immutable config where possible
  • alert on log service stopped, journal rotated oddly, or auth.log truncated
  • gaps in logs are themselves a signal

What to alert on

Raw logs are not detection; alerts are. A handful carry most of the value. Many failed logins followed by a success means a brute force worked. A login from a new country or host. Sudo to root by a user who never does that. A service account spawning an interactive shell. A new SUID file or an edit to sudoers. And the logging service stopping. Each maps to a real attacker step, and each is rare enough in normal operation to be worth a human's attention.

High-signal alerts
  • many failed logins then a success (brute force worked)
  • login from a new country/host
  • sudo to root by an unusual user
  • service account runs a shell
  • new SUID file, sudoers edited
  • logging stopped or logs cleared

Common mistakes

Mistakes. Keeping logs only on the host, so the attacker deletes them. Leaving the journal in memory, so a reboot wipes it. Running no auditd, so there is no record of commands. Collecting everything and alerting on nothing, which is just expensive storage. Clocks not synchronised, so you cannot line up events across machines. No retention policy, so logs vanish before an investigation starts. And never running a drill to confirm the pipeline actually works.

Avoid these
  • logs only on the host
  • journal not persistent
  • no auditd, so no command record
  • collecting everything, alerting on nothing
  • clocks not synced (bad timeline)
  • no retention, logs gone in days
  • never testing with a drill

Say it like this

In the interview: I rely on the auth log and the journal for logins and sudo, and on auditd for command execution and access to sensitive files like the shadow file and the sudoers configuration. I ship everything off the box to a SIEM in near real time so an attacker cannot erase it, keep clocks synchronised for a clean timeline, and alert on the high-signal events: brute force that succeeded, unusual sudo, a service account spawning a shell, and logging being stopped.

In the interview
  • "auth.log and the journal for logins and sudo, and auditd for command execution and sensitive
  • file access. I ship everything
  • off-box to a SIEM so it cannot
  • be erased, keep clocks synced, and alert on brute force, odd
  • sudo, service-account shells
  • and logging being stopped."

Interview questions

Q1Where does Linux record logins and sudo use?

In the authentication log: /var/log/auth.log on Debian and Ubuntu, /var/log/secure on Red Hat-based systems. It records SSH logins (accepted and failed), sudo and su use, and account changes, making it the first place to triage suspicious access.

Q2What is journald and why make it persistent?

The systemd journal, read with journalctl, collects logs from services, the kernel and the system, filterable by unit, user, time and priority. Setting Storage=persistent keeps it across reboots, so a reboot (which an attacker may force) does not erase the evidence.

Q3What is auditd?

The Linux audit framework: a kernel-level, rule-driven system that records specific events such as execution of commands, writes to watched files, and reads of sensitive files like /etc/shadow. Rules carry keys, and logs are queried with ausearch.

Q4Which auditd rules are most useful for security?

Watches on writes to system directories and sudoers/SSH config, reads of /etc/shadow, new SUID files and kernel module loads, use of su/sudo/passwd, and execve by service accounts. Start from a CIS-aligned ruleset and tune out noise.

Q5Why must logs be shipped off the host?

Logs stored only locally can be altered or deleted by an attacker who compromises the host, and clearing them is a common early step. Forwarding them in near real time to a central SIEM preserves evidence the attacker can no longer reach.

Q6How do you detect log tampering?

Forward logs before they can be deleted, make audit logs append-only where possible, and alert on tampering signals: the logging service stopped, the journal cleared, or auth.log truncated. Unexpected gaps in the logs are themselves a signal.

Q7What are high-signal events to alert on?

Many failed logins followed by a success, logins from new locations, unusual sudo to root, a service account spawning a shell, new SUID files, edits to sudoers, and the logging service being stopped. Each maps to a real attacker step and is rare in normal use.

Q8Why does clock synchronisation matter for logs?

Investigations correlate events across many machines by time. If host clocks drift, the timeline is wrong and causes and effects appear out of order, so keeping NTP in sync is essential for accurate incident reconstruction.