BLOG POSTS
Track User Activity with whois, w, and last

Track User Activity with whois, w, and last

Table of Contents

Why Bother Tracking User Activity?

If you run a server (cloud, VPS, dedicated, Dockerized or not), you need to know what’s happening on it. This isn’t just about paranoia or security (though that’s a big part). It’s about responsibility. Who’s logged in? Who did what? Was it your colleague, a bot, or (gulp) an attacker? Or did you just forget you left that tmux session running in 5 terminals? Knowing who’s who and what’s what is the first step to real server mastery.

This article is your hands-on, no-nonsense guide to tracking user activity with three classic (and still awesome) Linux tools: whois, w, and last. We’ll show you why they’re essential, how to use them, and how to get them up and running—fast.

A Real-World Nightmare: Who Did This?

It’s Monday morning. The website is down. Production DB is missing half its tables. Your CEO just called. “Who changed the database last night?”

You open your terminal, heart pounding. You have a dozen users with SSH keys. Maybe a former contractor? Maybe a script gone rogue? Maybe you? (Wait, did you do something last night after those energy drinks?) This situation is way too real for a lot of us.

Enter user tracking tools. They’re your black box flight recorder for the server, giving you the timeline, the names, the IPs, the when and the where. Let’s make sure you’re ready before disaster hits.

What Are whois, w, and last (and why do YOU need them)?

Let’s break it down without the man-page jargon:

  • whois: Not a “who is logged in” command! It queries domain/IP registration info. Want to see who owns the IP that just SSH’d in? whois has your back.
  • w: Who’s on the system right now? What are they doing? Are they idle or active? This is your “who’s at the party” tool.
  • last: Want to see a history of logins and logouts? This is your time machine. Find out who logged in, when, from where, and how long they stayed.

These tools are lightweight, pre-installed (or installable in a flash), and work on almost every Unix-like system out there. No need for heavy monitoring stacks. Sometimes you just need raw info, now.

How Do These Tools Work? Short Geeky Deep-Dive

  • w: Reads from /var/run/utmp (active user sessions). Combines who’s logged in, what commands they’re running, uptime, and load averages. Think of it as peeking at the guestbook plus the security cams.
  • last: Parses /var/log/wtmp—the long-term login/logout record. It’s a rolling log, so you can scroll way back (unless log rotation ate your history).
  • whois: Contacts public domain/IP registration servers. It’s your “who’s behind this IP” detective—no Linux internals here, just internet sleuthing.

Super-geek note: If you want to automate or parse, both w and last have output formats you can script.

Use Cases: From “Whodunnit?” to “Who’s Online Right Now?”

  • Security Audits: Who logged in from that weird IP at 3AM?
  • Debugging: Is that heavy process running because someone’s terminal is still open?
  • Resource Management: Are there idle users hogging RAM?
  • Accountability: Trace a change back to the user session (combine with ps, history).
  • Forensics: After an incident, reconstruct the timeline.
  • IP Sleuthing: Spot unknown IPs—then use whois to see if it’s a friendly AWS box or a VPN exit node from somewhere sketchy.
  • Compliance: Quick checks for auditors: “Show me who’s logged in now and who accessed last week.”
  • Automation: Trigger scripts when someone logs in (hello, last and w in cron jobs).

Quick Setup: Step-By-Step Guide

1. Install the Tools (if they’re not there already)

Most distros come with w and last (part of procps or util-linux), but whois might need a quick install.

  • Debian/Ubuntu: sudo apt-get install whois
  • RHEL/CentOS/Fedora: sudo yum install whois or sudo dnf install whois
  • Alpine: apk add whois

2. Basic Usage: The Commands You Need

  • w — See who’s logged in and what they’re doing.
  • last — View a scrollback of logins (and logouts).
  • whois 8.8.8.8 — Find out who owns an IP address.

Practical Example:

w
(You’ll see a table with users, their source IPs, idle times, and what they’re running.)

last -a | head -20
(Shows the last 20 login events, with host/IP at the end.)

whois 203.0.113.42
(Shows you the ISP/organization that owns that IP.)

3. Diagram: How It Fits Together

+------------+    +---------------+    +-----------+
|  User SSH  | -> |    w/last     | -> |  You/Admin |
+------------+    +---------------+    +-----------+
                                    \-> |  whois    | -> [Internet registry]

User connects ➡️ You check with w/last ➡️ If suspicious, whois their IP.

Want more control? Spin up a VPS or dedicated server for your experiments and monitoring!

Mini Glossary: Real-Talk Definitions

  • utmp: The now log. Tracks current logins.
  • wtmp: The history log. Tracks logins/logouts.
  • Idle Time: How long someone’s session has been doing nothing.
  • TTY: Terminal name. Like a “seat” at the server table.
  • IP Address: Where someone’s connecting from (can be a clue, or a red herring).

Examples, Stories, and a Comic Metaphor Table

Comic Metaphor: The Server as a Nightclub

Tool Nightclub Role Superpower Weakness
w The Bouncer Knows who’s inside, what they’re drinking (process), and if they’re dancing (active) or snoozing (idle) Doesn’t remember who left the club 2 hours ago
last The Security Camera Rewinds the tape, sees who came and went—and when If the tape’s overwritten, memories are gone
whois The Detective Can find out if that mysterious guest is a VIP or a known troublemaker from another town Doesn’t know what they’re doing *inside* the club

Positive Example:

You see a process eating CPU. w shows user alice is running a Python script. You call her, realize it’s legit, crisis averted.

Negative Example:

You notice a login from Russia at 2AM. last confirms it’s never happened before. whois says it’s a known hosting provider. You dig deeper, find a compromised account, and lock it down.

Beginner Mistakes, Myths, and Similar Tools

  • Myth:whois tells me who’s logged in right now.”
    Reality: It’s about domain/IP ownership, not current users!
  • Myth:w and last are enough for security.”
    Reality: They’re a great start, but combine with auditd, journalctl, or psacct for deeper tracking.
  • Similar Tools: who, users, lastlog, finger — all worth exploring for different spins on user info.
  • Beginner Mistake: Not rotating logs; wtmp can get huge or be lost in rotation!
  • Beginner Mistake: Not checking for sudo or root escalation in session logs.

“Use This If…” Geeky Flowchart

👀 ➡️ Need to know who's on the server *now*?
    |
    +--> Yes: Use w or who | +--> No: Want to know who was on *before*? | +--> Yes: Use last | +--> No: Want to know who owns an IP/domain? | +--> Yes: Use whois | +--> No: Try ps, auditd, or advanced monitoring.

Links:

Cool Automation Ideas & Scripting Magic

  • Alert if a new IP logs in:
    # Simple Bash: Notify on new login IP
    last -a | head -20 | grep -v -F -f known_good_ips.txt | mail -s "Unknown SSH Login" you@example.com
    
  • Get a daily report of active users:
    echo "Current users:" > /tmp/daily_users.txt
    w >> /tmp/daily_users.txt
    mail -s "Daily User Activity" you@example.com < /tmp/daily_users.txt
    
  • Auto-whois any new IP that appears:
    for ip in $(last -a | awk '{print $NF}' | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'); do
      if ! grep -q $ip known_ips.txt; then
        whois $ip >> suspicious_ips.txt
      fi
    done
    

Fun Fact: You can pipe w or last output into awk, grep, or even dashboards for live monitoring!

Short Fiction: The Day the Logs Saved the Day

“Why is the server crawling?” I wondered, sipping my cold coffee. w showed three users logged in, but one session was running a find / -delete. “Who the heck is ‘bob’?” last revealed ‘bob’ had never logged in from that IP before. whois said it was a VPN exit node in another country. Seconds later, I killed the process, locked the account, blocked the IP, and sent the logs to the security team. Disaster averted, thanks to three humble terminal commands.

Conclusion & Recommendations

Why use w, last, and whois? Because they’re dead simple, always there, scriptable, and often all you need for fast, effective user tracking on your server. They’re your first line of defense, your audit trail, and your answer to “Who’s on my box?”

How? Install in seconds, run from any shell, combine for deeper insight. Automate for peace of mind.

Where? On ANY server you control: your dev box, your production VPS, your Docker host, or your big iron dedicated machine. Trust me: you’ll sleep better.

Want a box to experiment on? Check out VPS hosting or order a dedicated server for your own mini SOC playground.

Remember: the best time to set up user tracking was yesterday. The next best time is right now.



This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked