Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. while IFS=", " read username password
  2. do
  3. if [ $(id -u) -eq 0 ]; then
  4. egrep "^$username" /etc/passwd >/dev/null
  5. if [ $? -eq 0 ]; then
  6. echo "$username already dabs on this device!!"
  7. exit 1
  8. else
  9. pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  10. useradd -m -p $pass $username -s /bin/bash
  11. [ $? -eq 0 ] && echo "User has been added to the System!" || echo "Oof, failed yeet the person into /etc/passwd."
  12. usermod -a -G sudo $username
  13. [ $? -eq 0 ] && echo "User has been added to the sudo group!" || echo "Oof, failed to yeet person into the sudo group."
  14. mkdir /home/$username/.ssh
  15. ssh-keygen -t rsa -f /home/$username/.ssh/id_rsa -b 2048 -P ''
  16. [ $? -eq 0 ] && echo "User keys have been generated " || echo "Oof, failed to randomly assign 2048 bits to a user as a key."
  17. cp /home/$username/.ssh/id_rsa.pub /home/$username/.ssh/authorized_keys
  18. [ $? -eq 0 ] && echo "User keys have assigned to the authorized keys list." || echo "Oof, failed to yeet the key into the authorized_keys file."
  19. echo "The private key for $username is: " >> certlist && cat /home/$username/.ssh/id_rsa >> certlist
  20. [ $? -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!"
  21.  
  22. fi
  23. else
  24. echo "Only root may add a user to the system..."
  25. exit 2
  26. fi
  27. done < userlist.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement