Created
June 22, 2018 08:43
-
-
Save zined/fdd3431c1ed7f04535597ee699817e3b to your computer and use it in GitHub Desktop.
get-public-keys-for-users-in-group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
USERS="$( aws iam get-group --group-name ssh --query 'Users[].UserName' --output text )" | |
for USER in $USERS; do | |
PUBLIC_KEY_IDS="$( aws iam list-ssh-public-keys --user-name $USER --query 'SSHPublicKeys[].SSHPublicKeyId' --output text )" | |
for PUBLIC_KEY_ID in $PUBLIC_KEY_IDS; do | |
PUBLIC_KEY=$( aws iam get-ssh-public-key --user-name $USER --ssh-public-key-id $PUBLIC_KEY_ID --encoding SSH --query 'SSHPublicKey.SSHPublicKeyBody' --output text ) | |
echo "user=${USER}, key=${PUBLIC_KEY}" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment