Created
July 10, 2018 07:21
-
-
Save vedarthk/3d2b2c49ae1e03d6d8e3eda17b21627a to your computer and use it in GitHub Desktop.
Add users from IAM into the machine
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 +e | |
aws iam list-users --query "Users[].[UserName]" --output text | \ | |
while read User; do | |
UserName="$User" | |
# sanitize username from IAM | |
UserName=${UserName//+([@.])/""} | |
echo "username => $UserName" | |
if id -u "$UserName" >/dev/null 2>&1; then | |
echo "$UserName exists" | |
else | |
/usr/sbin/adduser --shell /bin/bash --disabled-password --gecos "" $UserName | |
echo "${UserName} ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/${UserFileName}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment