useful_scripts/check_key.sh

15 lines
606 B
Bash
Raw Normal View History

2023-03-28 11:34:40 -03:00
#!/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