1 #!/bin/bash
 2 
 3 #########################################################################
 4 # Cycle through all users on a server to determine the type of
 5 # OpenSSH keys they use.  Output a summarized total count for each type.
 6 #
 7 # This only works for the OpenSSH public key format.
 8 #########################################################################
 9 
10 for user in /home/*; do
11   # add the first line from each user's authorized_keys files
12   readarray -t -O "${#array[@]}" array < <(awk '{print $1}' "$user/.ssh/authorized_keys" 2>/dev/null)
13   readarray -t -O "${#array[@]}" array < <(awk '{print $1}' "$user/.ssh/authorized_keys2" 2>/dev/null)
14 done
15 
16 # sort and count the instances of key types
17 (IFS=$'\n'; sort <<< "${array[*]}") | uniq -c