Skip to content
Lesson: Session RecordsSwitch
← Security Operations

Security investigations

Session Records

Use login records to see who is or was on a Linux system.

A session starts when a user logs in and ends when they log out. Linux keeps records that show who is on the system now and who was before.

Who is here now

bash
$ who
alice    pts/0        2026-03-03 09:10 (198.51.100.4)

You see the user, terminal, login time and, for remote logins, the source. w adds what each session is doing. On systems with systemd, loginctl lists sessions too:

bash
loginctl list-sessions
loginctl show-session 12

Use a session ID from the first command. Columns differ between versions.

Past logins

bash
$ last -n 3
alice    pts/0        198.51.100.4     Tue Mar  3 09:10   still logged in
deploy   pts/1        192.0.2.17       Mon Mar  2 17:02 - 17:20  (00:18)
reboot   system boot  6.8.0-generic    Mon Mar  2 08:00   still running

last traditionally reads /var/log/wtmp. sudo lastb reads failed logins from /var/log/btmp. Some newer distributions have replaced or removed these traditional tools, for example with wtmpdb, because of the old file format. If a command is missing, check your distribution's documentation.

Gaps and limits

Not everything creates a record. A command run as ssh host uptime has no terminal and may not appear in who or last, although the SSH daemon still logs the authentication. Services and scheduled jobs are not interactive logins either.

Records can also be rotated away, so an empty result may just mean the file is new. A user with root can alter them. Compare them with the journal or a remote log copy.

Shell history is not a record

A shell history file such as ~/.bash_history is a convenience for the user. It can be edited, disabled or never written, and often lacks times. Do not treat it as proof of what happened. For reliable records of actions, use central logs and audit rules.

Ending a session

If you must end a session you own or are authorised to manage:

bash
sudo loginctl terminate-session 12

This ends its processes, so confirm the ID first. During an investigation, save the evidence before ending anything, and follow your organisation's procedure.

Try it

Run who, loginctl list-sessions and, if available, last -n 5 on your own machine. Match one entry across them. The processes and cron lab helps you inspect processes.

Check your understanding

Session Records

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.