Skip to content

Linux Foundations / Manage a Linux host ยท Step 45 of 50

Lesson: Authentication LoggingSwitch
โ† Linux Foundations

System administration

Authentication Logging

Track logins, sudo use and failed attempts using auth logs, last and lastb.

Authentication logs record who logged in, who tried and failed, and who used sudo. They matter for troubleshooting access and for spotting attacks.

Where they live

  • Debian and Ubuntu with rsyslog: /var/log/auth.log
  • Red Hat, Fedora and related: /var/log/secure
  • Any systemd system: the journal

Without rsyslog the text files may not exist. These logs are restricted, so use sudo.

Reading events

$ sudo grep sshd /var/log/auth.log
Jan  5 10:12:25 web01 sshd[2201]: Failed password for invalid user admin from 203.0.113.9 port 51514 ssh2
Jan  5 10:13:02 web01 sshd[2210]: Accepted publickey for sam from 192.0.2.15 port 40022 ssh2: ED25519 SHA256:...

invalid user means no such account exists. Accepted means a successful login, with the method shown. Newer OpenSSH versions may log some lines as sshd-session.

Use of sudo is recorded too:

Jan  5 10:15:40 web01 sudo:      sam : TTY=pts/0 ; PWD=/home/sam ; USER=root ; COMMAND=/usr/bin/apt update

In the journal, filter by unit. The SSH unit is ssh on Debian and Ubuntu and sshd on Red Hat and Fedora:

$ sudo journalctl -u ssh --since today
$ sudo journalctl _COMM=sudo

Login history

last reads /var/log/wtmp and lists past logins and reboots:

$ last -n 3
sam      pts/0        192.0.2.15       Mon Jan  5 10:13   still logged in
reboot   system boot  6.12.0           Mon Jan  5 09:00   still running

sudo lastb shows failed attempts from /var/log/btmp. These are binary files, so do not read them with cat. Some newer distributions are replacing these tools (for example last with wtmpdb), and lastb may be missing, as on Debian 13.

What to watch for

  • Many failures from one address in a short time suggest password guessing.
  • A successful login you cannot explain, especially after failures, needs investigation.
  • sudo commands run by unexpected users.

To reduce guessing, prefer SSH keys, disable password logins once keys work, and consider a tool such as fail2ban. Keep a session open while changing SSH settings so you do not lock yourself out.

Try it

Run last to view your own logins. Then look for sudo entries from today. You can explore accounts and access files in the accounts and access lab.

Check your understanding

Authentication Logging

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.