Skip to content
Linux TLDR
  • 🏠 Home
  • 🐧 Topic
    • All in One
    • DevOps
      • Ansible
      • AWS
      • Docker
      • Git
      • Jenkins
      • Kubernetes
    • Hardware
      • Raspberry Pi
    • How to
    • Linux Commands
      • Builtin Commands
      • Curl Commands
      • Homebrew Commands
      • MySQL Commands
      • SSH Commands
    • Linux Distributions
      • Alma Linux
      • Debian
      • Fedora
      • Kali Linux
      • Linux Mint
      • Manjaro
      • Red Hat
      • Ubuntu
    • News & Updates
    • Package Installer
    • Programming
      • Bash Scripting
      • C/C++
      • Go Lang
      • Java
      • Javascript
      • Node Js
      • Php
      • Python
      • Ruby
    • Reviews
    • Tools
    • Troubleshooting
    • Tutorials
    • Weekly Roundup
    • What is
  • πŸ•΅οΈ Privacy Policy
  • πŸ“§ Contact Us
  • πŸ“– About
    • πŸͺΆ Write an Article
    • πŸ”— Follow Us
    • 🎁 Donate

How to Check User’s Login History in Linux

Linux TLDR
Last Updated: April 1, 2025
Reading time: 4 minutes

A Linux server is operated by multiple users who can login and logout at any given time without any restriction (of course, they should have the proper privileges).

In an occasion like a data breach, you might want to track user activity to investigate the incident, and as a sysadmin, you might want to know who, when, and from where logged into the target machine.

In this case, you can use the last command, a fantastic built-in Linux utility.

Table of Contents

Toggle
  • Tutorial Details
  • What is the Last Command in Linux?
  • Usage of the Last Command
  • How to Check a Specific User’s Login History
  • How to Check Login History Based on TTY
  • Last Command Options
    • Limit the Entries to N Number in the Output
    • Display the Login History For Today and Yesterday
    • Display the Login History For a Specific Date
    • Display the Login History For Range of Dates
    • Display the Login History for the Last Few Days
    • Display the Reboot History
    • Display the Shutdown History
    • Display the Hostname Field in the Last Column
    • Hide the Hostname Field From the Output
    • Display the Full Login and Logout Timestamp
  • Bonus Tip! How to Check a User’s Failed Login Attempts

Tutorial Details

DescriptionShow a Log of the User’s Login History
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisiteslast
Internet RequiredNo

What is the Last Command in Linux?

The last command is a tool that sysadmins often use to keep track of user sessions on the server. It can list information about users, such as their usernames, when they log in and out of the system, where they log in from, etc.

This information is pulled from the β€œ/var/log/wtmp” file, which is always modified in the event of a user’s login and logout. You can check out our dedicated article on this topic.

This article will focus mostly on how to use the last command and its different options.

  • Find the Last Logged-In Users in Linux with Lastlog Command

Usage of the Last Command

The last command takes two arguments: one is the option, and the other is the username or TTY (all are optional).

$ last [OPTION] [USERNAME/TTY]

If you run the last command without any arguments, the following screen will appear:

last command output

Note that this record is listed in reverse chronological order; the first will be the latest record; in this case, the β€œdavid” user has recently logged in to the system.

The following is an explanation of each field in the output:

  1. The username, note that in the event of a system reboot or shutdown, the β€œlast” shows special users β€œreboot” and β€œshutdownβ€œ.
  2. The tty user used to start the login process. β€œpts/*” means via SSH, β€œtty*” means via terminal, and β€œ0:” means via the desktop environment.
  3. The host name or the IP address from which the user logged in.
  4. The login and logout times.
  5. The duration of the user session; if the user fails to logout, the message β€œno logout” appears. If the user is still active, it will show β€œstill running” in place of duration.

Now, let’s move on to the next section.

How to Check a Specific User’s Login History

If you know all the user’s login names on the target machine, then you can use that to filter out the result for a particular user.

$ last david

Output:

Checking a specific user login history

From the above picture, it appears that β€œdavid” has initiated the login process multiple times on the β€œJan 12” date.

How to Check Login History Based on TTY

Unlike the previous command, you can investigate the user based on TTY; for example, you can specify β€œpts/*” to check the login attempts held on the target machine via SSH.

$ last pts/3

Output:

Checking a login history based on TTY

From the above picture, it appears that the β€œdavid” and β€œjake” users logged in to the target machine on the β€œJan 12” date via SSH.

Now, let’s move on to the next section to check all the options offered by this command.

Last Command Options

The last command supports a variety of options that can limit the entries in the output, display login history for a specific or range of dates, hide/show columns, etc.

Limit the Entries to N Number in the Output

The β€œ-N” option, where β€œN” refers to any positive integer, is used to specify the number of lines (or entries) to display in the output.

$ last -5

The above command will return the latest five entries in the output.

Limiting the entries in the output of the last command

Display the Login History For Today and Yesterday

The following command will display the login history for today and yesterday, whereas the β€œ-s” flag represents β€œsince” and the β€œ-t” flag represents β€œuntilβ€œ.

$ last -s yesterday -t today

Output:

Display the login history for today and yesterday

Display the Login History For a Specific Date

The β€œ-p” flag can be used to show the log of login history for a particular date specified in β€œYYYY-MM-DD” format.

$ last -p 2022-11-18 

Output:

Display the login history for a specific date

Display the Login History For Range of Dates

The following command will display the login history from β€œ2022-11-16” to β€œ2022-12-11β€œ.

$ last -s 2022-11-16 -t 2022-12-11

Output:

Show the Login History for a Date Range

Display the Login History for the Last Few Days

The following command will display the login history for the last five days.

$ last -s -5days

Output:

Display the login history for the last five days

Display the Reboot History

Each time a user reboots the system, a new entry is written in the file with a special β€œreboot” username that can be used to show a log of all reboots since the log file was created.

The following command will show all the entries with system reboots and run levels changes using the β€œ-x” flag.

$ last -x reboot

Output:

Display the reboot history and runlevels changes

Display the Shutdown History

Similar to the previous command, whenever users shutdown the system, a new entry is written in the file with the special β€œshutdown” username.

$ last -x shutdown

Output:

Display the shutdown and runlevels changes

Display the Hostname Field in the Last Column

The β€œ-a” flag will move the hostname field to the last column so that the result doesn’t get cut off.

$ last -a

Output:

Moving the hostname field to the last column

Hide the Hostname Field From the Output

The β€œ-R” flag will remove the hostname field from the output.

$ last -R

Output:

Remove the hostname field from the output

Display the Full Login and Logout Timestamp

The β€œ-F” flag will display the timestamp entries for login and logout in full format.

$ last -F

Output:

Display the timestamp for entries in full format

And here comes the end of all examples.

Bonus Tip! How to Check a User’s Failed Login Attempts

Isn’t it good to look up a user’s login and logout history? But while investigating the user’s login history, you must also consider the failed login attempts held on the target machine.

The last command does not display the failed login attempts by users; for this, you have to use another command-line tool known as the lastb command.

The following command will show a log of all the failed login attempts made by the users on the target machine.

$ sudo lastb

Output:

Display the user's failed login attempts

The above output shows that the β€œjake” user tried to access the target machine via SSH with the wrong authentication information.

Let’s finish this article here; I think you can dig further by yourself.

If you have any questions or queries related to this topic, then feel free to ask them in the comment section.

Till then, peace!

SHARE:

Recommended Articles

πŸ”—How to Install Zabbix Server on Ubuntu 24.04 (Noble Numbat)
πŸ”—Stellar Repair for MySQL – Product Review
πŸ”—How to Install RQuickShare (NearbyShare/QuickShare) on Linux
πŸ”—How to Install RabbitMQ Server on Linux (Quick Guide)
πŸ”—How to Use Chattr Command in Linux (for Beginners)
πŸ”—How to Setup SOCKS5 Proxy Server on Linux Using MicroSocks
πŸ”—Reset the WordPress Admin Password Using CLI (via 2 Methods)
πŸ”—How to Check Python Version in Linux (via 3 Methods)
πŸ”—How to Check PHP Version in Linux (via 4 Methods)
πŸ”—[Fixed] pkg-config script could not be found in Linux

Latest

Install zabbix server on ubuntu

How to Install Zabbix Server on Ubuntu 24.04 (Noble Numbat)

mysql database recovery tool

Stellar Repair for MySQL – Product Review

RQuickShare Linux

How to Install RQuickShare (NearbyShare/QuickShare) on Linux

Install RabbitMQ Server on Linux

How to Install RabbitMQ Server on Linux (Quick Guide)

chattr command

How to Use Chattr Command in Linux (for Beginners)

Newsletter

Explore the latest Linux news, tutorials, tips, and resources to master open-source technology.

Social Handles

quora

Your help is needed

AI and ad blockers are significantly impacting advertising revenue. Donate now to support funding for this independent site.

🎁 Make a Donation
Linux TLDR © 2026 - Discover, Learn, and Master Linux with Us 🐧