who, w, and last: Inspecting Logins and Sessions
Who is using this server right now?
who to see who is logged in right now, w to see what they are doing, and last to see who logged in in the past. These three go together nicely once you learn them.What You'll Learn
- How to list currently logged-in users with
who - How to check each user's activity and server load with
w - How to look back through past login history with
last - How to inspect reboot and boot history with
last reboot - When to use
who/w(now) vslast(past)
1. What's the difference between who, w, and last?
Conclusion:
whoandwshow who is logged in right now, whilelastshows past login history.wis more detailed thanwhoand reveals what each user is doing.
who and w show the live login state; last shows history. who is the simple one, and w adds "what they're doing" on top of it.| Command | What it shows | Type of info |
|---|---|---|
who |
Who is logged in now | Now (live) |
w |
Now + each user's activity | Now (live, detailed) |
last |
Past login history | Past (log) |
who and w read live session data (/var/run/utmp), while last reads an accumulated log (/var/log/wtmp). That's why only last can show people who have already logged out.
2. How do I see who is logged in now?
Conclusion: Just type
whoto list each logged-in user's name, terminal, and login time.
who on its own. No arguments or options needed.$ who
lina tty1 2026-06-05 09:12 linny pts/0 2026-06-05 10:03 (192.168.1.20)
tty1 and pts/0?tty1 is a console attached directly to the machine; pts/0 is a virtual terminal over the network (like SSH). The (192.168.1.20) on the right is the source IP, shown for remote logins.Columns (left to right)
- Username
- Terminal (
tty= physical,pts= pseudo-terminal = remote connection) - Login date and time
- Source host / IP (if any)
who am i and you'll see only your own session line. Note the spaces — it's three separate words.$ who am i
linny pts/0 2026-06-05 10:03 (192.168.1.20)
who am i (with spaces, three words) and whoami (no spaces, one word) are different. whoami is a separate command that prints only your username; it is not an option of who. They're easy to mix up.
3. How do I see what each user is doing?
Conclusion:
wadds to whatwhoshows — for each user it displays the command they are running right now, plus the server's load average, all on one screen.
w is for. The top line shows the overall server state, and each row below shows the command each user is running.$ w
10:15:32 up 2 days, 3:41, 2 users, load average: 0.15, 0.10, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT lina tty1 - 09:12 1:03m 0.20s 0.20s -bash linny pts/0 192.168.1.20 10:03 2.00s 0.10s 0.05s w
up), how many users are logged in, and the load average. A higher load average means busier. The three numbers are averages over the last 1, 5, and 15 minutes.Key columns in w
USER/TTY/FROM: who, which terminal, from whereLOGIN@: login timeIDLE: time since last activity (longer = more idle)WHAT: the command running right now
WHAT tells me I'm just sitting in -bash (a shell), and you're running w.w -h, or narrow to one user with w lina.$ w -h lina
lina tty1 - 09:12 1:03m 0.20s 0.20s -bash
4. How do I see past login history?
Conclusion:
lastshows past login history, newest first. It includes people who have already logged out, so you can trace who logged in, when, and from where.
last. It lists login and logout records, newest first. There can be a lot, so start by limiting the count with -n.$ last -n 5
linny pts/0 192.168.1.20 Fri Jun 5 10:03 still logged in lina tty1 Fri Jun 5 09:12 still logged in linny pts/0 192.168.1.20 Thu Jun 4 18:40 - 19:55 (01:15) lina pts/1 192.168.1.31 Thu Jun 4 14:02 - 17:30 (03:28) reboot system boot 6.8.0-generic Thu Jun 4 08:00 still running
still logged in and others say - 19:55 (01:15).still logged in means "still online now." 18:40 - 19:55 (01:15) means "logged in at 18:40, logged out at 19:55, for a duration of 1 hour 15 minutes." For past sessions you also get the logout time and duration.last -n 5 shows only the 5 newest entries. last -5 does the same thing. History piles up, so narrowing the count first makes it much easier to read.
5. How do I check reboots or a specific user?
Conclusion: Use
last rebootfor reboot/boot history, andlast usernameto filter to one user's logins.
reboot line in that history. Can I see when the server rebooted?last reboot lists just the boot times. Handy for tracking "when did it go down / come back up."$ last reboot
reboot system boot 6.8.0-generic Thu Jun 4 08:00 still running reboot system boot 6.8.0-generic Mon Jun 1 07:55 - Jun 4 07:58 (2+23:03)
last. last lina lists only lina's logins.$ last lina
lina tty1 Fri Jun 5 09:12 still logged in lina pts/1 192.168.1.31 Thu Jun 4 14:02 - 17:30 (03:28) lina tty1 Wed Jun 3 09:30 - 18:10 (08:40)
To inspect failed logins, use lastb (the btmp log), not last. lastb needs administrator privileges, so run sudo lastb. It helps you spot signs of intrusion, such as many failures from an unfamiliar IP.
Mini exercise (click to open)
Find out "how many users are logged in now" and "the 3 most recent login records," each with a different command.
Hint: The count appears in the header line of w (or the number of rows from who). For history, narrow to 3 entries with last -n 3.
6. Common pitfalls and fixes
Conclusion: Most trouble comes from three things: confusing
whoamiwithwho am i, misreadingstill logged ininlast, and looking for failed logins withlast.
| Symptom | Cause | Fix |
|---|---|---|
| Only a username appears | Using whoami |
Use who for a list, w for detail |
who am i returns an error |
Wrong spacing | Three words with spaces: who am i |
last output is too long to read |
Showing the full history | Limit with last -n 10 |
Failed logins don't show in last |
Looking at the success log (wtmp) | See failures with sudo lastb (btmp) |
Unsure what still logged in means |
Confused with the duration format | It means "still online now" |
When in doubt, follow this order: who is here now → who, what they're doing / load → w, look back into the past → last.