How do I list the N last successful and unsuccessful login attempts for my user when I log in with e.g. ssh on Linux?

5,831

Solution 1

You can use the last command to show that last logins, maybe put it in /etc/profile.d:

last $USER

However, I would be careful outputting any more to the screen than necessary, because some automated login bits (non-interactive) don't like extra output and fail. Maybe put in /etc/bashrc and detect if it is a login shell with shopt -q login_shell, and only run if it is.

Solution 2

last -10 will show last 10 logins.

Take a look over man last

Share:
5,831

Related videos on Youtube

Vegard
Author by

Vegard

Studied computer science at the University of Oslo. Now working for Ksplice at Oracle.

Updated on September 18, 2022

Comments

  • Vegard
    Vegard almost 2 years

    This seems like such a basic security feature I'm surprised it's not already standard.

  • zecrazytux
    zecrazytux over 11 years
    .bashrc is sourced for both login and interactive shells wheras .bash_profile (or .profile for other shells) is sourced only for login shells.
  • lsd
    lsd over 11 years
    Yes, but if you want it for all users, rather than modifying every .bashrc or .bash_profile on the system, then you would modify /etc/profile, /etc/bashrc, or drop a file in /etc/profile.d.
  • zecrazytux
    zecrazytux over 11 years
    right, so replace the dots by /etc/ in my previous comment ;) "Maybe put in /etc/bashrc and detect if it is a login shell with shopt -q login_shell, and only run if it is." => better use /etc/profile