Created
July 5, 2019 19:46
-
-
Save y2k-shubham/edf0f5faf7f642bec17b0d39801e2d91 to your computer and use it in GitHub Desktop.
Bash script to (1) Read list of usernames from text file (2) Create linux users (3) Set and display random 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 | |
for user in $( cat users.txt ); do | |
# create user | |
sudo useradd --create-home $user | |
# generate random password | |
PASSWD="$(pwgen -cnsv -N 1 32)" | |
# set password | |
echo $user:$PASSWD | chpasswd | |
# print message | |
echo "Created user $user with password $PASSWD" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference links