Skip to content

Instantly share code, notes, and snippets.

@y2k-shubham
Created July 5, 2019 19:46
Show Gist options
  • Save y2k-shubham/edf0f5faf7f642bec17b0d39801e2d91 to your computer and use it in GitHub Desktop.
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
#!/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
@y2k-shubham
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment