Skip to content

Instantly share code, notes, and snippets.

@artburkart
Created August 17, 2016 20:16
Show Gist options
  • Save artburkart/e71c9f8e3c13007b4feeca697035b2aa to your computer and use it in GitHub Desktop.
Save artburkart/e71c9f8e3c13007b4feeca697035b2aa to your computer and use it in GitHub Desktop.
Find IAM user with given AWS Access Key ID
#!/bin/bash
# Usage: bash find_user_by_aws_access_key.sh SOME_AWS_ACCESS_KEY
# This script finds the user in the account who has a given access key
ACCESS_KEY=$1
for user in `aws iam list-users | jq -r '.Users[].UserName'`; do
USER=`aws iam list-access-keys --user $user | jq '.AccessKeyMetadata[] | select(.AccessKeyId == "'"$ACCESS_KEY"'")'`
if [ -n "$USER" ]; then
echo "$USER"
exit 0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment