Account activity can span several sessions. Linux login history from last shows retained sessions with the user, remote address, login and logout times, and available history range.
The last command reads the login database written by the system's session stack. Traditional systems store records in /var/log/wtmp, while newer Debian and Ubuntu releases may provide last through wtmpdb and store the same class of records in a SQLite database. ISO timestamps make session times easier to compare with authentication logs and ticket times.
Login history is only as complete as the database and retention policy on that host. Empty output, missing files, or reboot-only records do not prove the account was never used, and failed attempts may live only in authentication logs on current distributions. Authentication and account-management logs can help corroborate unexpected sessions.
Steps to check user login history in Linux:
- List recent sessions for the target account.
$ last --limit 5 --hostlast --time-format iso admin admin ssh 2026-11-05T18:34:29+0000 - 2026-11-05T18:34:33+0000 (00:00) 127.0.0.1 wtmpdb begins 2026-11-05T18:33:43+0000
The account name here is admin. The final column is the recorded remote address; 127.0.0.1 means the connection came from the same host. wtmpdb may label an SSH session as ssh rather than pts/N. On legacy hosts the final line may say wtmp begins instead of wtmpdb begins. Ubuntu stores the SQLite database at /var/log/wtmp.db; upstream wtmpdb defaults to /var/lib/wtmpdb/wtmp.db.
- Check whether the account was logged in at a specific time.
$ last --present "2026-11-05 18:34:30" --limit 5 --time-format iso admin admin ssh 127.0.0.1 2026-11-05T18:34:29+0000 - 2026-11-05T18:34:33+0000 (00:00) wtmpdb begins 2026-11-05T18:33:43+0000
--present matches sessions open at the supplied time, such as the timestamp in a ticket or alert. The input time uses the host's local timezone. Current sessions are covered by showing logged-in users.
- Include reboot and shutdown records that may explain session gaps.
$ last --system --limit 5 --time-format iso admin ssh 127.0.0.1 2026-11-05T18:34:29+0000 - 2026-11-05T18:34:33+0000 (00:00) s-reboot system boot 7.0.14-linuxkit 2026-11-05T18:33:43+0000 - still running wtmpdb begins 2026-11-05T18:33:43+0000
--system includes shutdown records alongside login and boot entries. Some wtmpdb output labels soft reboot entries as s-reboot.
- Check failed SSH password attempts since midnight on a systemd host.
$ sudo journalctl --unit ssh.service --unit sshd.service --since today --grep 'Failed password' --no-pager Nov 05 18:35:22 server sshd-session[624]: Failed password for admin from 127.0.0.1 port 43482 ssh2
The unit filters cover the usual ssh.service and sshd.service names, including messages from their per-session processes. A custom SSH service needs its own unit name. This query covers password failures since local midnight; no matches do not rule out other authentication failures or missing older logs. lastb reads /var/log/btmp on systems that still provide it. Non-systemd hosts and broader authentication checks are covered by checking authentication logs.
- Confirm the retained login-history range with an unfiltered listing.
$ last --time-format iso admin ssh 127.0.0.1 2026-11-05T18:34:29+0000 - 2026-11-05T18:34:33+0000 (00:00) s-reboot system boot 7.0.14-linuxkit 2026-11-05T18:33:43+0000 - still running wtmpdb begins 2026-11-05T18:33:43+0000
A record limit can change the begins time reported by wtmpdb, so this range check uses no account filter or limit. The begins line describes the available database, not proof that no earlier sessions existed. For older activity, rotated files, exported wtmpdb databases, central logs, or backups may hold additional records.