who, w, and last: Inspecting Logins and Sessions
What you'll be able to do
- Check who is logged in now and what each of them is doing with `who` and `w`
- Trace past logins and reboot history with `last`
- Choose between the commands that show "now" and the one that shows "the past"
Prerequisites (read these first)
Who is using this server right now?
who to see who is logged in right now. Use w to see what they are doing. Use last to see who logged in in the past.Learn the escape route first: when the screen looks stuck
last prints a lot of history. The output can scroll on and on, as if it will never stop. Here is how to get out.
| What you see | How to get out |
|---|---|
| Output scrolls on and never ends | Press Ctrl+C to stop it |
A : or (END) appears and it pauses |
A pager is running - the tool that shows long output one screen at a time, such as less. Press q to leave it |
who prints nothing at all |
Not a failure. Nobody is logged in. On WSL or in a container the record file can simply be empty |
| You never wanted that much output | Limit the count up front: last -n 5 |
who, w, and last only display information. Running them changes no settings, so try them without worry.
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, and last shows history.who is the simple one. w adds "what they're doing" to the same picture.What a session is
A session is one continuous stretch of use, from the moment a user logs in until they log out. "Login session" and "connection" are used for much the same idea. If the same person logs in from two places, that is two sessions.
| 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 (/run/utmp, which does not exist in some environments), 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, terminalAn interactive program that reads the commands you type and runs them., 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, such as 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)
Lina's Mistake: Confusing whoami with who am i
whoami and all I got was a name. No terminal, no time.whoami — no spaces, one word — prints only your username.who family?who am i — with spaces, three words — pulls just your own line out of the who output.who am i (with spaces, three words) and whoami (no spaces, one word) are different commands. whoami is not an option of who. They're easy to mix up, so watch out for it.
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.What load average means
Load average is a number for how much work is piled up, including work still waiting its turn. Treat it as a busyness gauge. Think of a checkout line: it is close to the number of people standing in it. Smaller means quieter.
Key columns in w
USER/TTY/FROM: who, which terminal, from whereLOGIN@: login timeIDLE: time since last activity (longer = more idle)JCPU/PCPU: how much CPU time was used (safe to skip at first)WHAT: the command running right now
WHAT tells me I'm just sitting in -bash (a shell), and you're running w.w -h when it gets in the way. 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.-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.
6. Mini Exercises - Get Hands-On
Conclusion: Three tasks — the current head count, recent history, and reboot history — to make the "now vs past" split stick.
Exercise 1: Count Who Is Logged In Now
Task: Find out how many people are logged into this server right now.
Show Hint 1 (Direction)
Two commands show "now." Pick the one that puts the head count on its first line.
Show Hint 2 (Command name)
Use w. Its header line contains users. Counting the rows from who works too.
Show Answer
$ w
10:15:32 up 2 days, 3:41, 2 users, load average: 0.15, 0.10, 0.05
The 2 users part is the head count.
Exercise 2: Show the 3 Most Recent Logins
Task: Display past login history, limited to the 3 newest records.
Show Hint 1 (Direction)
Use the command that shows the past. On its own it prints far too much, so add the option that limits the count.
Show Hint 2 (Command name)
Use last. Limit with -n COUNT. Writing last -3 does the same thing.
Show Answer
$ last -n 3
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)
Exercise 3: Show the Server's Reboot History
Task: Display the history of when this server booted.
Show Hint 1 (Direction)
The history command can be narrowed by adding a word after it. Add the word that stands for booting.
Show Hint 2 (Command name)
Use last, followed by reboot.
Show Answer
$ last reboot
reboot system boot 6.8.0-generic Thu Jun 4 08:00 still running
who and w, the past is last" — I think I can remember that.w first. Head count, load, and activity all arrive on one screen.7. 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" |
last prints only "wtmp begins ..." |
The history file (/var/log/wtmp) is empty |
Common on WSL and in containers. Try a real server or VM |
When in doubt, follow this order: who is here now → who, what they're doing / load → w, look back into the past → last.
Today's Three-Line Summary
wholists who is here now, andwadds their activity and the load. Start with these two to read the current statelastis the past. Narrow it withlast -n 5, and uselast rebootfor boot history alonewhoami(one word) andwho am i(three words) are different commands. For failed logins, usesudo lastb