Skip to content

Instantly share code, notes, and snippets.

@vedarthk
Created July 10, 2018 07:21
Show Gist options
  • Save vedarthk/3d2b2c49ae1e03d6d8e3eda17b21627a to your computer and use it in GitHub Desktop.
Save vedarthk/3d2b2c49ae1e03d6d8e3eda17b21627a to your computer and use it in GitHub Desktop.
Add users from IAM into the machine
#!/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