#!/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