Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # check if executed as root
  4.  
  5. if [[ ${UID} != 0 ]]
  6. then
  7. echo 'You are not root'
  8. exit 1
  9. fi
  10.  
  11. # get details for the new account
  12.  
  13. read -p 'Create user: ' USERNAME
  14. read -p 'Full name: ' FULLNAME
  15. read -p 'Set password: ' PASSWORD
  16.  
  17. # create the account
  18.  
  19. useradd $USERNAME -c "$FULLNAME" -m
  20.  
  21. # check creation was successul
  22.  
  23. if [[ $? != 0 ]]
  24. then
  25. echo 'Unable to create user'
  26. exit 1
  27. fi
  28.  
  29. # set password and set as expired
  30.  
  31. echo $PASSWORD | passwd --stdin $USERNAME
  32. passwd -e $USERNAME
  33.  
  34. # echo details
  35.  
  36. echo "Username: $USERNAME"
  37. echo "Password: $PASSWORD"
  38. echo "Host: $HOSTNAME"
  39.  
  40. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement