Skip to content
-
Subscribe to our Howsnip.com website & never miss our best posts. Subscribe Now!
howsnip_logo How Snip

Tech Tutorials, IT Guides & Cybersecurity Tips

  • Home
  • About Us
  • Pages
    • Privacy Policy
    • Write For Us
    • Terms and Conditions
  • Sitemap
  • Contact Us
Advertise
Home ยป How to Track User Logins on Linux Using who, last, ac, lslogins, and lastlog
Track User Logins
Posted inLinux

How to Track User Logins on Linux Using who, last, ac, lslogins, and lastlog

Posted by Chetan Soni October 23, 2026

Monitoring user login activity is an important part of Linux system administration. Whether you’re troubleshooting access issues, auditing user activity, or simply checking who is using a server, Linux provides several built-in tools that make the job easy.

In this tutorial, you’ll learn how to track user logins and review login history using the who, last, ac, lslogins, and lastlog commands. These tools provide insights into current sessions, historical login records, user connection times, and account activity.

Prerequisites

Before you begin, ensure that:

  • You have access to a Linux system.
  • You can open a terminal session.
  • You have sufficient privileges to view system login records where required.

Check Currently Logged-In Users with the who Command

The who command displays users who are currently logged in to the system. In addition to showing active users, it provides information such as:

  • Username
  • Login time
  • Terminal session
  • Remote login source or IP address (when applicable)

Run the following command:

who

Tracking User Logins Howsnip

This command reads current login session information and displays all users who are actively connected to the system.

View Login History with the last Command

While who only shows active sessions, the last command lets you review historical login records. It displays logins in reverse chronological order, starting with the most recent entries.

Run:

last | head -6

Tracking User Logins Howsnip

What this command does

  • last reads login records from the system’s login database.
  • head -6 limits the output to the first six lines, making the results easier to read.

Make the Output Easier to Read

If the output contains multiple spaces, you can compress them into single spaces for cleaner formatting:

last | head -7 | tr -s " "

Tracking User Logins Howsnip

What this command does

  • last retrieves login history.
  • head -7 displays the first seven lines.
  • tr -s ” ” squeezes repeated spaces into a single space.

This can be useful when copying output into reports or logs.

Check Login Records Stored in the wtmp File

Linux stores login history in the /var/log/wtmp file. This file contains login and logout records that tools such as last use to display historical activity.

Important: /var/log/wtmp is a binary file. You cannot inspect it directly using commands such as cat, more, or grep.

Count User Logins from the Current wtmp File

The following script counts login entries for users with home directories under /home.

for user in `ls /home`
do
echo -n "$user: "
who /var/log/wtmp | grep "^$user " | wc -l
done

Tracking User Logins Howsnip

What this command does

  • ls /home lists regular users with home directories.
  • The loop processes each user individually.
  • who /var/log/wtmp reads login records from the wtmp file.
  • grep “^$user ” filters entries matching the current username.
  • wc -l counts the number of matching logins.

The result is a login count for each user.

Check the Oldest Record in the wtmp File

To see how far back your login records go, display the oldest entry:

who /var/log/wtmp | head -1

Tracking User Logins Howsnip

What this command does

  • Reads login records from the wtmp file.
  • Displays the first entry, which is typically the oldest available record.

This can help determine the retention period of your login history.

View wtmp File Start Information

You can also view login information for a specific user:

last howsnip

Tracking User Logins Howsnip

What this command does

  • Displays the login history for user howsnip.
  • Shows available records stored in the current login database.
  • Includes information about the beginning of the available wtmp history.

Replace howsnip with the username you want to investigate.

Analyze User Connection Time with the ac Command

The ac command reports how long users have been connected to the system.

This is useful for auditing usage patterns and login activity.

a) Display Daily Login Totals

Run:

ac -d | tail -5

Tracking User Logins Howsnip

This provides a quick overview of recent login activity.

b) Display User Connection Totals

To view connection totals by user:

ac -p

Tracking User Logins Howsnip

This is helpful when reviewing overall system usage.

Review User Accounts with the lslogins Command

The lslogins command provides detailed information about system and user accounts. By default, it displays both regular user accounts and system accounts.

Run:

lslogins | head -5

Tracking User Logins Howsnip

What this command does

  • Lists account information from system databases.
  • Displays login-related details, including the last login time when available.

You may notice many system accounts without login information because they typically do not log in interactively.

Show Only Regular User Accounts

To hide system accounts and display only user accounts:

lslogins -u

Tracking User Logins Howsnip

What this command does

  • The -u option filters the output to regular users.
  • Makes login information easier to review.
  • Display Detailed Information for a Specific User

To view detailed account information for a user:

lslogins howsnip

This command gathers information from account-related system files and displays details such as:

  • User ID (UID)
  • Login information
  • Default shell
  • Account-related settings

Replace howsnip with the username you want to inspect.

Tracking User Logins Howsnip

Check the Most Recent Login with lastlog

The lastlog command displays the most recent login information for users.

To check a specific user:

lastlog -u howsnip

Tracking User Logins Howsnip

What this command does

  • Shows the user’s most recent login.
  • Displays login time, terminal, and remote source information when available.

Replace howsnip with the appropriate username.

Conclusion

Linux includes several powerful utilities for tracking user logins and account activity. The who command shows current sessions, last provides login history, ac reports connection times, lslogins displays account details, and lastlog reveals the most recent user login.

By combining these tools, you can quickly audit user access, investigate activity, and gain better visibility into how your Linux systems are being used.

Tags:
ac command Linuxcheck user logins Linuxlast command Linuxlastlog commandLinux login historyLinux login monitoringLinux user activitylslogins commandTrack UserTrack User HowsnipTrack User LinuxTrack User Loginstrack user logins LinuxTrack User Logswho command Linux
Chetan Soni
Chetan Soni is the voice behind howsnip.com, where he shares practical insights, tips, and inspiration to help readers simplify life and achieve more every day.
View All Posts

Post navigation

Previous Post
Ubuntu Server with Nginx How to Set Up Ubuntu Server with Nginx, PHP, MySQL, SSL, Composer, and Adminer
Next Post
How to Work with Substrings and Text Extraction in Linux Using awk, cut, grep, sed, xargs, expr, and Bash Substrings Howsnip
Related posts
Install GitLab
Posted inLinux

How to Install GitLab on Ubuntu 26.04 Using Docker Compose

Posted by Chetan Soni
odoo 19
Posted inLinux

How to Deploy Odoo 19 on Ubuntu 24.04 Using Docker Compose and Caddy

Posted by Chetan Soni
Install Drupal Howsnip
Posted inLinux

How to Install Drupal on Ubuntu 26.04 with Apache, PHP, and MariaDB

Posted by Chetan Soni
Search
Categories
  • AI/ML 9
  • Cryptocurrency 2
  • Linux 118
  • Programming 11
  • Tech 38
  • Windows 15
Topattop_Banner
Recent Articles
  • 17 Best GitHub Repositories to Learn Python in 2026
  • How to Install GitLab on Ubuntu 26.04 Using Docker Compose
  • How to Deploy Odoo 19 on Ubuntu 24.04 Using Docker Compose and Caddy
  • How to Know If Your Windows License Is Permanent or Temporary
  • How to Install Drupal on Ubuntu 26.04 with Apache, PHP, and MariaDB
  • Microsoft Confirms LDAP Security Update Issue Affecting NetApp SMB Shares
  • Microsoft 365 Outage Explained: Why Outlook, Teams and Copilot Were Down for Over 24 Hours
  • How to Install PrestaShop on Ubuntu 26.04 Using Apache, MariaDB, and PHP
  • How to Install and Use Portainer on Ubuntu 26.04 for Docker Container Management
  • How to Install Traefik Reverse Proxy with Automatic SSL Using Docker Compose on Ubuntu
Useful Links
  • About Us
  • Advertise With Us
  • Contact Us
  • Privacy Policy
  • Sitemap
  • Terms and Conditions
  • Write For Us
Tech
  • 17 Best GitHub Repositories to Learn Python in 2026
  • How to Fix MySQL Server Has Gone Away Error When Importing a Large WordPress Database
  • 90+ Best Free Alternatives to Paid Software and Online Tools in 2026
  • [PHP2Shell] How to Check PHP Servers for CVE-2026-109618 and CVE-2026-109619
  • Major Cybersecurity Incidents: eMudhra, SBI Data Breach, PHP2Shell, Node.js and LiteLLM Security Risks
  • eMudhra Certificate Compromise Triggers Global Security Response After Eight CA Keys Exposed
  • Simple SIEM Home Lab with Elastic Cloud – Setup and Monitoring Guide
  • Apple iOS 27 Is Here – 9 Exciting New Features Every iPhone User Should Try
  • How to Detect CVE-2026-89049 Attacks Using AWS CloudTrail
  • 25 Commonly Asked AppSec & InfoSec MCQs with Answers and Explanations
Linux
  • How to Install GitLab on Ubuntu 26.04 Using Docker Compose
  • How to Deploy Odoo 19 on Ubuntu 24.04 Using Docker Compose and Caddy
  • How to Install Drupal on Ubuntu 26.04 with Apache, PHP, and MariaDB
  • How to Install PrestaShop on Ubuntu 26.04 Using Apache, MariaDB, and PHP
  • How to Install and Use Portainer on Ubuntu 26.04 for Docker Container Management
  • How to Install Traefik Reverse Proxy with Automatic SSL Using Docker Compose on Ubuntu
  • How to Self-Host Uptime Kuma with Docker on Ubuntu for Free Server Monitoring
  • 11 Proven Ways to Secure a Linux Server Against Cyber Threats
  • How to Install Redis on Ubuntu 24.04 – Step-by-Step Guide
  • How to Install Apache Kafka 4.0 on Ubuntu with KRaft Mode
Programming
  • Learn CRUD Operations in PHP Using PDO and MySQL in 15 Practical Steps
  • 25 Essential JavaScript Acronyms Every Developer Should Know
  • Top 100 JavaScript MCQs Every Full Stack Developer Should Know
  • 30-Day MERN Stack Challenge Roadmap to Become a Full-Stack Developer
  • Top 20 Advanced SQL Commands You Need To Know
  • 6 Essential SQL Operations Every Cybersecurity Professional Must Know
  • Build a Simple AJAX-Based Comment System in PHP and MySQL (With CAPTCHA Verification)
  • Top 10 Tricky SQL Interview Questions (With Examples and Explanations)
  • 100 HTML/CSS/JavaScript Interview Questions with Answers
  • 50+ Essential Web Development Abbreviations You Need to Know in 2025
Copyright 2026 - How Snip. All rights reserved.
Scroll to Top