Advertisement
Guest User

Untitled

a guest
Jan 14th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. # This script creates an account on the local system.
  3. # You will be prompted for the account name and password.
  4.  
  5.  
  6. # Make sure the script is being executed with superuser privileges
  7.  
  8. if [[ "${UID}" -ne 0 ]]
  9. then
  10. echo 'Please run with sudo or as root.'
  11. exit 1
  12. fi
  13.  
  14. # Ask for the users name.
  15. read -p 'Enter the username to create: ' USER_NAME
  16.  
  17. # Ask for the real name.
  18. read -p 'Enter the full name of the person who this account is for: ' COMMENT
  19.  
  20. # Ask for the password.
  21. read -p 'Enter the password to use for the account: ' PASSWORD
  22.  
  23. # Create user
  24. useradd -c "${COMMENT}" -m ${USER_NAME}
  25.  
  26. # Check to see if the useradd command succeeded
  27. # We dont want to the tell the user that an account was created when it hasnt been
  28. if [[ "${?}" -ne 0 ]]
  29. then
  30. echo 'The account could not be created.'
  31. exit 1
  32. fi
  33.  
  34. # Set the password for the user.
  35.  
  36. echo ${PASSWORD} | passwd --stdin ${USER_NAME}
  37.  
  38. if [[ "${?}" -ne 0 ]]
  39. then
  40. echo 'The password for the account could not be set.'
  41. exit 1
  42. fi
  43.  
  44. # Force user to change password on first login.
  45. passwd -e ${USER_NAME}
  46.  
  47. # Diplay the username, password and the host where the user was created.
  48.  
  49. echo
  50. echo 'username:'
  51. echo "${USER_NAME}"
  52. echo
  53. echo 'password:'
  54. echo "${PASSWORD}"
  55. echo
  56. echo 'host:'
  57. echo "${HOSTNAME}"
  58. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement