Created
March 17, 2016 16:08
-
-
Save timmow/c955f5fbc9d08ef8848c to your computer and use it in GitHub Desktop.
Create aws users password / key and encrypt
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
#!/bin/bash | |
set -euo pipefail | |
function create_user { | |
USERNAME=$1 | |
RECIPIENT=$2 | |
aws iam create-user --user-name $USERNAME | |
ACCESS_KEY_JSON=$(aws iam create-access-key --user-name $USERNAME) | |
ACCESS_KEY_ID=$(echo $ACCESS_KEY_JSON | jq -r '.[] | .AccessKeyId') | |
SECRET_ACCESS_KEY=$(echo $ACCESS_KEY_JSON | jq -r '.[] | .SecretAccessKey') | |
aws iam add-user-to-group --user-name $USERNAME --group-name Contractors | |
gpg --output $USERNAME-$AWS_ACCOUNT.gpg --encrypt --recipient $RECIPIENT <<EOF | |
ACCESS_KEY_ID: $ACCESS_KEY_ID | |
SECRET_ACCESS_KEY: $SECRET_ACCESS_KEY | |
EOF | |
} | |
function create_password { | |
USERNAME=$1 | |
RECIPIENT=$2 | |
PASSWORD=$(apg -a1 -n1 -m10) | |
aws iam create-login-profile --user-name $USERNAME --password $PASSWORD --password-reset-required | |
gpg --output $USERNAME-$AWS_ACCOUNT-password.gpg --encrypt --recipient $RECIPIENT <<EOF | |
Password: $PASSWORD | |
EOF | |
} | |
export AWS_ACCOUNT=dev | |
create_user test [email protected] | |
create_password test [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment