Skip to content

Instantly share code, notes, and snippets.

@akase244
Last active January 28, 2022 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akase244/2be2cde1481691fbbd3671e942edaa47 to your computer and use it in GitHub Desktop.
Save akase244/2be2cde1481691fbbd3671e942edaa47 to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
awk -F':' '{print $6}' /etc/passwd |sort |uniq | while read line
do
if [ -e "${line}/.ssh/authorized_keys" ]; then
echo ${line}
for i in $(seq 1 $(wc -l ${line}/.ssh/authorized_keys |awk '{print $1}')); do
sed -n ${i}p ${line}/.ssh/authorized_keys |grep -v -e '^\s*#' -e '^\s*$' |grep -q -e 'ssh-rsa ' -e 'ssh-dsa ' -e 'ssh-dss ' -e 'ssh-ed25519 '
if [ $? -eq 0 ]; then
ssh-keygen -l -f <(sed -n ${i}p ${line}/.ssh/authorized_keys)
fi
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment