After an access handoff or suspicious alert, an account's last recorded SSH login in Linux shows its login time and remote IP address. That record helps establish when the account was last used remotely.

On Linux, last reads the host login-accounting database and prints records from newest to oldest. Some distributions provide it through wtmpdb, while others read /var/log/wtmp. The lastlog2 -u user command, where available, reports only the latest saved login for an account, which may be a local login rather than SSH.

Login accounting must be enabled, and rotation or retention limits can remove older records. Some SSH activity, including sessions without a terminal, may be absent depending on the host's logging setup. An empty result does not prove that the account has never connected through SSH.

Steps to check the last SSH login in Linux:

  1. Show the newest recorded login for the target account on the SSH server.
    $ last -i -n 1 user
    user     pts/0        203.0.113.10     Fri Nov  6 15:16 - 15:16  (00:00)
    
    wtmpdb begins Fri Nov  6 15:16:37 2026

    The user argument is the account name being checked. The -i option requests a numeric source address, and -n 1 shows only the newest matching record. The columns show the account, terminal, remote address, login time, logout time, and session length.

  2. List the account's retained logins to find the newest row with a remote address.
    $ last -i user
    user     pts/0                         Fri Nov  6 15:16 - 15:16  (00:00)
    user     pts/0        203.0.113.10     Fri Nov  6 15:16 - 15:16  (00:00)
    
    wtmpdb begins Fri Nov  6 15:16:37 2026

    Rows run from newest to oldest. Here, the first row is a newer local login with no remote address, and the next row is the latest SSH login, from 203.0.113.10 on Fri Nov 6 at 15:16. On some hosts the terminal column says ssh rather than pts/N.

    The address may belong to a jump host or NAT gateway. If the expected row is missing or its origin is uncertain, check the authentication logs. For a longer timeline, use the login-history check; for sessions that are open now, use the active SSH connection check.

Share this guide