added check_key.sh

This commit is contained in:
celso 2023-03-28 11:34:40 -03:00
parent 387337d41e
commit 8245712ab8
1 changed files with 14 additions and 0 deletions

14
check_key.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
#run as root
#$1 is username
for i in $(awk '{print $2}' "/home/${1}/.ssh/authorized_keys"); do
dude="$(base64 -d <<< "${i}" | sha256sum | awk '{print $1}' | xxd -r -p | base64)"
for j in $(grep "Accepted publickey for ${1}" /var/log/auth.log | grep -o "SHA256.*$" | sed 's/^SHA256://g' | sort | uniq); do
[ "${dude:0:-1}" = "${j}" ] && {
_users="$(grep "${i}" /home/${1}/.ssh/authorized_keys | awk '{print $3" logged in"}')"
lastlog_time="$(tac /var/log/auth.log | grep -m1 "${j}" | awk '{print $1" "$2" "$3" "}')"
echo "${lastlog_time} ${_users}"
}
done
done