Created
March 28, 2019 15:39
-
-
Save gmirsky/44fdec425f2dc38f9f76824c959c292c to your computer and use it in GitHub Desktop.
Add users with temporary password to group
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 | |
| # | |
| # | |
| # Run as root or sudo su | |
| # | |
| #set -x | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "This script requires elevated permissions." | |
| echo "Please run this script as sudo or root." | |
| exit | |
| fi | |
| # | |
| # Script assumes that the groups have already been created. | |
| # | |
| USERS_TO_PROVISION="dabbas nfraihat ookour salqsous" | |
| TEMPORARY_PASSWORD="Scub@d1v3r" | |
| GROUP_TO_BE_ADDED_TO="soc_tier_1" | |
| # | |
| # | |
| # Iterate the string variable, USERS_TO_PROVISION, using the loop to provision | |
| # the Tier one user ids. | |
| for USER_TO_BE_PROVISIONED in $USERS_TO_PROVISION; do | |
| useradd $USER_TO_BE_PROVISIONED | |
| chage -m -1 $USER_TO_BE_PROVISIONED | |
| echo $TEMPORARY_PASSWORD | passwd --stdin $USER_TO_BE_PROVISIONED | |
| passwd --expire $USER_TO_BE_PROVISIONED | |
| usermod -aG $GROUP_TO_BE_ADDED_TO $USER_TO_BE_PROVISIONED | |
| done | |
| # | |
| USERS_TO_PROVISION="aabdallah almunayyer mmohtasib" | |
| GROUP_TO_BE_ADDED_TO="soc_tier_2" | |
| # | |
| # Iterate the string variable, USERS_TO_PROVISION, using the loop to provision | |
| # the Tier two user ids. | |
| for USER_TO_BE_PROVISIONED in $USERS_TO_PROVISION; do | |
| useradd $USER_TO_BE_PROVISIONED | |
| chage -m -1 $USER_TO_BE_PROVISIONED | |
| echo $TEMPORARY_PASSWORD | passwd --stdin $USER_TO_BE_PROVISIONED | |
| passwd --expire $USER_TO_BE_PROVISIONED | |
| usermod -aG $GROUP_TO_BE_ADDED_TO $USER_TO_BE_PROVISIONED | |
| done | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment