Skip to content

Instantly share code, notes, and snippets.

@vedarthk
Created July 10, 2018 07:29
Show Gist options
  • Save vedarthk/b275263111529de632b879ad173c9210 to your computer and use it in GitHub Desktop.
Save vedarthk/b275263111529de632b879ad173c9210 to your computer and use it in GitHub Desktop.
Authorize keys from IAM in SSH
#!/bin/bash -e
if [ -z "$1" ]; then
exit 1
fi
UserName="$1"
# replace the sanitized characters with omitted while importing before fetching data from IAM
/opt/awscli/bin/aws iam list-ssh-public-keys --user-name $UserName --query "SSHPublicKeys[?Status == 'Active'].[SSHPublicKeyId]" --output text | \
while read KeyId; do
/opt/awscli/bin/aws iam get-ssh-public-key --user-name $UserName --ssh-public-key-id "$KeyId" --encoding SSH --query "SSHPublicKey.SSHPublicKeyBody" --output text
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment