Linux servers

Who logged in last weekend?

Monday morning, security asks who logged in to the six database servers over the weekend. The servers are reachable only through a jump host, the auth log is readable only by root, and the weekend has already been rotated into older, partly compressed files.

  1. Add the six servers, through the jump host

    Import them from ~/.ssh/config or PuTTY, or add them by hand. Pick the jump host as their jump server, and switch on sudo for reading — the auth log belongs to root. Nothing is installed on the servers.

    Host editor of a database server with the jump host set as jump server and sudo switched onHost editor of a database server with the jump host set as jump server and sudo switched on
  2. One data source for all six, including last week's files

    Point it at /var/log/auth.log* (/var/log/secure* on Red Hat and its relatives). That covers auth.log, auth.log.1 and the compressed auth.log.2.gz.

    Data source with the path pattern /var/log/auth.log* on the hosts db01 to db06Data source with the path pattern /var/log/auth.log* on the hosts db01 to db06
  3. Search the weekend

    Saturday 00:00 to Sunday 24:00. The first try, session opened, also finds every cron job — thousands of lines. Accepted finds only the logins. The search runs on each server; only matching lines cross the network.

    Search criteria with the text Accepted and the weekend as time rangeSearch criteria with the text Accepted and the weekend as time range
  4. One table: who, from where, on which server

    All 33 logins from six servers, sorted by time. More than half are the backup job's key early on Saturday. The chart's second block is Sunday night — all on db04.

    Result table with sshd Accepted publickey lines on db04 on Sunday night, the chart above with two blocks, early Saturday and Sunday nightResult table with sshd Accepted publickey lines on db04 on Sunday night, the chart above with two blocks, early Saturday and Sunday night
  5. Explain it, and hand it over

    On db04: an admin's planned maintenance — and a deploy key from a build server that nobody expected there. Export the list as CSV or HTML for security. Exporting needs a licence; everything up to here works in the free version.

Good to know

  • ConnectionsSSH with password or key. Jump servers, also several in a chain. Hosts can be imported from ~/.ssh/config or PuTTY.
  • Root-only logssudo or sudo su per host; a read-only account with sudo rights for the log files is enough.
  • Old filesA pattern such as auth.log* includes rotated and .gz files.
  • Log files onlyRetrospective reads log files. Hosts that log only to the systemd journal need rsyslog, or a journal export to a file.
  • NetworkThe search runs on the server; only matching lines are transferred.
  • Other systemsThe same works on macOS and Unix hosts, and on small devices with busybox and dropbear SSH.

Related notes: Why Retrospective searches logs where they are written

Retrospective is a desktop app for Windows, macOS and Linux. Send yourself the link and install it on your computer.

Send me the link

SSH connections in the manual