Created
January 11, 2019 11:17
-
-
Save D4rk4/bcbea2d39415ec5a2c7153f1a0aa6ea0 to your computer and use it in GitHub Desktop.
Just create users in AWS IAM from file (random one time passwords)
This file contains hidden or 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 | |
delim='---------CUTH HERE---------' | |
input='/opt/scripts/aws/aws-users.list' | |
create_user () { | |
profile=$1 | |
user=$2 | |
fxsdpolicy=$3 | |
pass=`strings /dev/urandom|grep -o '[[:alnum:]]'|head -n 16|tr -d '\n'|sed 's/^/!/;s/$/6/'` | |
#### | |
ID=`aws --profile ${profile} iam list-users --out text | head -1 | cut -f2 | awk -F'::' '{print $2}' | cut -f1 -d:` | |
aws --profile ${profile} iam create-user --user-name ${user} > /dev/null | |
aws --profile ${profile} iam create-login-profile --password-reset-required --user-name ${user} --password ${pass} > /dev/null | |
#aws iam add-user-to-group --group-name ${grp} --user-name ${user} | |
aws --profile ${profile} iam attach-user-policy --user-name ${user} --policy-arn 'arn:aws:iam::aws:policy/IAMUserChangePassword' | |
aws --profile ${profile} iam attach-user-policy --user-name ${user} --policy-arn "arn:aws:iam::${ID}:policy/${fxsdpolicy}" | |
#### | |
echo ${delim} | |
echo 'Hello,' | |
echo '' | |
echo 'You have been given access to the AWS Management Console for the Amazon Web Services. You can get started by using the sign-in information provided below.' | |
echo '' | |
echo "Sign-in URL: https://$ID.signin.aws.amazon.com/console" | |
echo "User name: ${user}" | |
echo "Password: ${pass}" | |
echo '' | |
echo '' | |
echo 'Sincerely,' | |
echo 'Your AWS Account Administrator' | |
echo ${delim} | |
} | |
while read line | |
do | |
profile=`echo $line | cut -d, -f1` | |
user=`echo $line | cut -d, -f2` | |
fxsdpolicy=`echo $line | cut -d, -f3` | |
create_user ${profile} ${user} ${fxsdpolicy} | |
done <${input} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment