Admin-Ahead Community

Linux => General Linux => Topic started by: jerrys on November 25, 2017, 10:46:02 pm

Title: Script to check the login attempts of a particular user into the server.
Post by: jerrys on November 25, 2017, 10:46:02 pm
Hi all,

Here is a bash script to check the number of login attempts of a user into the server, this script displays all the users in the system and provides you the option to check the login attempt details of a particular user.

------------------------------------------------------------------------------------------
#!/bin/bash
echo ======================================================================
echo The users in the System are:
awk -F'[/:]' '{if ($3==0) print $1}' /etc/passwd
awk -F'[/:]' '{if ($3 >=500 && $3 != 65534) print $1}' /etc/passwd
echo ""
echo Enter the name of the user whose logins needs to be counted:
read username
echo ""
echo The number of times the user $username has successfully logged into the custom container is
less /var/log/secure |grep $username | grep -ic accepted
echo ""

echo The number of failed login attempts of the user $username into the custom container is
less /var/log/secure |grep $username | grep "authentication failure" | wc -l
echo ""

echo ======================================================================

------------------------------------------------------------------------------------------
Please feel free to modify :)