wtmpdb Forensics: Reading wtmp.db on Debian 13 and openSUSE
wtmp.db for investigators: where wtmpdb stores logins on Debian 13 and openSUSE, the wtmp table column by column, SQL for sessions and boots, and tampering.
TL;DR. On Debian 13 (trixie) and openSUSE Tumbleweed, login history is no longer in /var/log/wtmp but in a SQLite database, wtmp.db, written by wtmpdb. It has one table, wtmp, with one row per session: the login creates the row and the logout fills in Logout. Times are microseconds since the epoch, UTC. Copy the file, open it read-only with any SQLite client, and keep in mind three things the old format did not prepare you for: last on Debian 13 is wtmpdb last, SSH rows written by sshd have no Service, and deleted rows are zeroed by Debian's SQLite build.
Why wtmp became a SQLite database
Classic wtmp is an array of struct utmp records. On x86_64 glibc keeps the time fields 32-bit so that 32-bit programs can share the file, and those fields overflow in January 2038 (see wtmp, btmp and lastlog forensics for the 384-byte layout). Fixing the struct would break every program that reads it, so Thorsten Kukuk (SUSE) wrote wtmpdb: a library, a PAM module (pam_wtmpdb.so), a CLI (wtmpdb) and an optional daemon, storing 64-bit microsecond timestamps in SQLite.
Where it lives
| System | Database | Notes |
|---|---|---|
| Upstream default, openSUSE | /var/lib/wtmpdb/wtmp.db | pam_wtmpdb.so is called from /etc/pam.d/postlogin-session |
| Debian 13 | /var/log/wtmp.db | /var/lib/wtmpdb/wtmp.db is a symlink to it (Debian patch db-in-var-log.patch) |
| Debian 13, rotated | /var/log/wtmp.db.1 … .4 | /etc/logrotate.d/wtmpdb: yearly, rotate 4, nocompress |
upstream wtmpdb rotate | wtmp_YYYYMMDD.db next to the database | Moves entries older than 60 days (default); Debian does not install the rotation service |
Debian specifics worth knowing before you draw conclusions:
lastis wtmpdb. util-linux in trixie no longer shipslast,lastborlastlog; thewtmpdbpackage installs/usr/bin/lastas a symlink towtmpdb. Itslastcannot read oldutmp-format files.- The upgrade imported the old wtmp. On first installation, the package converts an existing
/var/log/wtmpintowtmp.dbwithwtmpdb import. Rotated files such aswtmp.1are not converted, so on an upgraded bookworm host the period before the upgrade may exist in both formats, or only inwtmp.1. - No packages, no records.
wtmpdbandlibpam-wtmpdbmust be installed. A trixie host without them writes no login database at all; an absentwtmp.dbis not proof of deletion. Checkdpkg -l wtmpdb libpam-wtmpdb(or/var/lib/dpkg/statusin an image) first. - Failed logins are not in it. The database has no equivalent of btmp. Failed attempts are in auth.log and the journal.
The wtmp table, column by column
CREATE TABLE wtmp(ID INTEGER PRIMARY KEY, Type INTEGER, User TEXT NOT NULL,
Login INTEGER, Logout INTEGER, TTY TEXT, RemoteHost TEXT, Service TEXT) STRICT
| Column | Content |
|---|---|
ID | The SQLite rowid, assigned at insert: max(ID) + 1. Rows are inserted in time order, so IDs follow logins. |
Type | 1 BOOT_TIME (boots and shutdowns), 2 RUNLEVEL (non-systemd only), 3 USER_PROCESS (sessions). 0 (EMPTY) is defined but not written. |
User | Login name. For boot rows, reboot, or soft-reboot when systemd reports a soft reboot. |
Login | Session start, or boot time, in µs since 1970-01-01 UTC. The boot time is computed as now minus CLOCK_BOOTTIME, so it is the kernel boot, not the moment the service ran. |
Logout | Session end, or shutdown time for a boot row. NULL while the session is open, or if it never closed cleanly. |
TTY | pts/0, tty1, without /dev/. ~ for boot rows. PAM applications that set a fake TTY can store a generic string such as ssh. |
RemoteHost | Remote host or IP, or the X display. For boot rows, the kernel release (uname -r). |
Service | The PAM service that created the row (login, lightdm-greeter…), or NULL. |
Service is NULL for SSH logins on Debian 13. OpenSSH 10.0 writes to wtmpdb itself (loginrec.c calls wtmpdb_login() with no service), and Debian's PAM configuration loads pam_wtmpdb.so skip_if=sshd to avoid duplicate rows. Boot rows and rows imported from an old wtmp also have a NULL service. A pts/N row with a RemoteHost and no service is the normal shape of an SSH session there; do not read the empty column as a sign of tampering, and do not filter on Service = 'sshd'.
As with classic wtmp, only sessions that get a terminal are recorded: ssh host command, scp and sftp without a pty normally leave no row.
Collecting and opening it safely
# Debian 13 (live host or mounted image); on openSUSE use /var/lib/wtmpdb/wtmp.db*
cp --preserve=timestamps /var/log/wtmp.db* evidence/
sha256sum evidence/wtmp.db*
sqlite3 -readonly evidence/wtmp.db ".schema"
Copy the file before you query it, and open the copy read-only. wtmpdb leaves SQLite in its default rollback-journal mode (PRAGMA journal_mode returns delete), so you will normally find no -wal file. If a wtmp.db-journal or wtmp.db-wal exists, a write was in progress or someone opened the file with other settings: collect it with the database, because it may hold the newest rows or the previous content of changed pages. The file's mtime is the time of the last login, logout, boot or shutdown written to it.
SQL queries an examiner needs
All times below are converted with strftime('%Y-%m-%dT%H:%M:%fZ', Login/1e6, 'unixepoch'), which keeps milliseconds. datetime(Login/1000000, 'unixepoch') works too but drops them. Forgetting to divide is the classic mistake: the raw value is a 16-digit number.
Every session, with duration:
SELECT ID, User, TTY, RemoteHost, Service,
strftime('%Y-%m-%dT%H:%M:%fZ', Login/1e6, 'unixepoch') AS login_utc,
strftime('%Y-%m-%dT%H:%M:%fZ', Logout/1e6, 'unixepoch') AS logout_utc,
(Logout - Login) / 1000000 AS seconds
FROM wtmp WHERE Type = 3 ORDER BY Login;
Sessions without a logout, and whether a boot followed (what last prints as crash rather than still logged in):
SELECT w.ID, w.User, w.TTY, w.RemoteHost,
strftime('%Y-%m-%dT%H:%M:%fZ', w.Login/1e6, 'unixepoch') AS login_utc,
EXISTS (SELECT 1 FROM wtmp b WHERE b.Type = 1 AND b.Login > w.Login) AS boot_after
FROM wtmp w WHERE w.Type = 3 AND w.Logout IS NULL;
Boots, shutdowns and kernel versions. A boot row with no Logout followed by another boot is an unclean shutdown (power loss, crash, or a forced reset); a kernel change between boots dates an upgrade:
SELECT ID, User, RemoteHost AS kernel,
strftime('%Y-%m-%dT%H:%M:%fZ', Login/1e6, 'unixepoch') AS boot_utc,
strftime('%Y-%m-%dT%H:%M:%fZ', Logout/1e6, 'unixepoch') AS shutdown_utc
FROM wtmp WHERE Type = 1 ORDER BY Login;
Remote sources per account:
SELECT RemoteHost, User, COUNT(*) AS sessions,
strftime('%Y-%m-%dT%H:%M:%fZ', MIN(Login)/1e6, 'unixepoch') AS first_utc,
strftime('%Y-%m-%dT%H:%M:%fZ', MAX(Login)/1e6, 'unixepoch') AS last_utc
FROM wtmp WHERE Type = 3 AND COALESCE(RemoteHost, '') <> ''
GROUP BY RemoteHost, User ORDER BY sessions DESC;
Who was logged in at a given moment (here 2026-11-05 00:30 UTC):
SELECT ID, User, TTY, RemoteHost FROM wtmp
WHERE Type = 3
AND Login <= strftime('%s', '2026-11-05 00:30:00') * 1000000
AND (Logout IS NULL OR Logout >= strftime('%s', '2026-11-05 00:30:00') * 1000000);
wtmpdb last vs the old last
wtmpdb last mimics util-linux last and accepts most of its options:
TZ=UTC wtmpdb last -F -x -S -f wtmp.db # full times, shutdown rows, PAM service column
TZ=UTC wtmpdb last --time-format iso -f wtmp.db # ISO 8601 timestamps
wtmpdb last -s 2026-11-01 -t 2026-11-08 -f wtmp.db alice pts/0
wtmpdb last -j -f wtmp.db # JSON output
wtmpdb boottime -f wtmp.db # latest boot only
Points to keep in mind:
- It prints in the analysis machine's time zone, JSON output included; set
TZ=UTC. - It sorts by
Login, not byID, and does not print the ID, so the gaps and ordering anomalies below are invisible in its output. Use SQL for those. - Debian 13 ships wtmpdb 0.73. Upstream fixed
--present(-p) in 0.76, so on trixie answer "who was logged in at T" with the SQL above. -ftakes any file, so run it on your copy, not on the live database.
Tampering and gaps
wtmpdb has no integrity protection: anyone with root can run sqlite3 /var/log/wtmp.db "DELETE FROM wtmp WHERE ID = 42". What that leaves behind:
Gaps in ID. Deleting a row in the middle leaves a hole in the sequence:
SELECT ID + 1 AS first_missing, next_id - 1 AS last_missing
FROM (SELECT ID, LEAD(ID) OVER (ORDER BY ID) AS next_id FROM wtmp)
WHERE next_id > ID + 1;
Deleting the newest rows leaves no gap: ID is a plain INTEGER PRIMARY KEY without AUTOINCREMENT, so SQLite reuses the highest free number for the next login. Upstream wtmpdb rotate deletes the oldest rows, so a database that does not start at ID 1 is normal where that rotation runs.
Rows out of order. IDs are assigned at insert time, so Login should grow with ID. A row whose Login is earlier than the row before it was inserted later with a backdated time, or the clock was stepped (NTP correcting a bad RTC at boot is the benign case; check the journal for systemd-timesyncd or chrony time jumps):
SELECT ID, prev_id, (Login - prev_login) / 1e6 AS seconds_back
FROM (SELECT ID, Login, LAG(ID) OVER (ORDER BY ID) AS prev_id,
LAG(Login) OVER (ORDER BY ID) AS prev_login FROM wtmp)
WHERE Login < prev_login;
Edited logout times. A logout is an UPDATE of the session row, so a shortened or invented Logout leaves no extra row. Compare each session with sshd's session closed for user in auth.log, systemd-logind Removed session messages in the journal, and USER_END records in audit.log.
Deleted rows are gone on Debian. Debian builds libsqlite3 with SQLITE_SECURE_DELETE, so content removed through the system library (the sqlite3 CLI, Python's sqlite3 module) is overwritten with zeros, and carving freed pages finds nothing. Check what the host's library does with PRAGMA secure_delete; (1 means on) before you promise anything from unallocated space. A statically linked SQLite brought by an attacker would not have that default.
Missing sessions. As with classic wtmp, the strongest test is cross-source: an interactive SSH session in auth.log, the journal and audit.log, with a pts terminal, while wtmp.db covers that period without a matching row. On Debian 13, also check that openssh-server is the Debian build: an sshd compiled without wtmpdb support, combined with skip_if=sshd, records no SSH logins at all, which looks exactly like deletion.
lastlog2 alongside
lastlog moved to SQLite too, as lastlog2 in util-linux 2.40 and later: /var/lib/lastlog/lastlog2.db, table Lastlog2(Name TEXT PRIMARY KEY, Time INTEGER, TTY TEXT, RemoteHost TEXT, Service TEXT), one row per user name, Time in seconds. It is written by pam_lastlog2.so, independently of wtmpdb. A lastlog2 Time with no session starting within a few seconds of it in wtmp.db points to a deleted wtmp row (the two are written by different components, so allow a small offset), and a user whose latest wtmp session is newer than their lastlog2 entry points to an edited lastlog2.
SELECT Name, datetime(Time, 'unixepoch') AS last_login_utc, TTY, RemoteHost, Service FROM Lastlog2;
Parse it in the browser
Linux Log Parser reads wtmp.db and lastlog2.db directly, with no SQLite client. Drop them with auth.log, the journal and audit.log: boot rows become boot and shutdown events with the kernel version, sessions are paired and merged with sshd, logind and audit sessions on a single UTC timeline, a -wal file next to the database is applied, and interactive logins with no wtmp record are flagged. Everything is parsed locally; nothing is uploaded. For the classic binary files, see wtmp, btmp and lastlog forensics; for building the full timeline, the Linux log forensics timeline guide.