Skip to content

Instantly share code, notes, and snippets.

@zined
Created June 22, 2018 08:43
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 zined/fdd3431c1ed7f04535597ee699817e3b to your computer and use it in GitHub Desktop.
Save zined/fdd3431c1ed7f04535597ee699817e3b to your computer and use it in GitHub Desktop.
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