Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while IFS=", " read username password
- do
- if [ $(id -u) -eq 0 ]; then
- egrep "^$username" /etc/passwd >/dev/null
- if [ $? -eq 0 ]; then
- echo "$username already dabs on this device!!"
- exit 1
- else
- pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
- useradd -m -p $pass $username -s /bin/bash
- [ $? -eq 0 ] && echo "User has been added to the System!" || echo "Oof, failed yeet the person into /etc/passwd."
- usermod -a -G sudo $username
- [ $? -eq 0 ] && echo "User has been added to the sudo group!" || echo "Oof, failed to yeet person into the sudo group."
- mkdir /home/$username/.ssh
- ssh-keygen -t rsa -f /home/$username/.ssh/id_rsa -b 2048 -P ''
- [ $? -eq 0 ] && echo "User keys have been generated " || echo "Oof, failed to randomly assign 2048 bits to a user as a key."
- cp /home/$username/.ssh/id_rsa.pub /home/$username/.ssh/authorized_keys
- [ $? -eq 0 ] && echo "User keys have assigned to the authorized keys list." || echo "Oof, failed to yeet the key into the authorized_keys file."
- echo "The private key for $username is: " >> certlist && cat /home/$username/.ssh/id_rsa >> certlist
- [ $? -eq 0 ] && echo "User and Keypair creation was successful! Check the output file for details" || echo "OOPSIE WOOPSIE!! uWu We made a fucky wucky!! AA wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!"
- fi
- else
- echo "Only root may add a user to the system..."
- exit 2
- fi
- done < userlist.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement