Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get-public-keys-for-users-in-group
#!/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
You can’t perform that action at this time.