Skip to content Skip to sidebar Skip to footer

Script to Check User Login on VPS

I'm coming again bro. want to share a script to check the user who is logging in :D
right away. the steps:

1. Log in to your VPS via Putty

Spoiler 
Posted Gambar

2. after logging in: create a bash file (.sh) how:
Spoiler 
# nano check-user.sh

Spoiler 
Posted Gambar

3. copy the following code:

Spoiler 
#!/bin/bash
#
# Copyright by tokopcn.com
# ========================
#
data=( `ps aux | grep -i dropbear | awk '{print $2}'`);
echo "Checking user login";
echo "---";
for PID in "${data[@]}"
do
#echo "check $PID";
NUM=`cat /var/log/auth.log | grep -i dropbear | grep -i "Password auth succeeded" | grep $PID | wc -l`;
USER=`cat /var/log/auth.log | grep -i dropbear | grep -i "Password auth succeeded" | grep $PID | awk '{print $10}'`;
IP=`cat /var/log/auth.log | grep -i dropbear | grep -i "Password auth succeeded" | grep $PID | awk '{print $12}'`;
if [ $NUM -eq 1 ]; then
echo "$PID - $USER - $IP";
fi
done
echo "---";
echo "tokopcn.com";

Spoiler 
Posted Gambar

4. press ctrl + x >> press Y >> and than enter

5. give permission to the file
Spoiler 
# chmod +x cek-user.sh

Spoiler 
Posted Gambar

6. execute the command as follows

Spoiler 
# ./check-user.sh
here's the result bro -> Posted Gambar