daily pastebin goal
41%
SHARE
TWEET

New user with bash script

neal777 Oct 17th, 2017 (edited) 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. if [ "$(id -u)" = "0" ]; then #Check if the user is root or not
  3. var=$((501 + RANDOM % 1000001)) #random generator between 501 and 1000001
  4. echo "This is user script by Sandesh Koirala."
  5. username="newbee"
  6. password="newbee"
  7. #read -p "Enter username : " username
  8. #read -s -p "Enter password : " password
  9. echo "$username:x:$var:0:10:180:14:0:" >> /etc/shadow #store userdata and password expiration
  10. echo "$username:x:$var:$var::/home/$username:/bin/bash" >>
  11. /etc/passwd #write the username and profile number
  12. echo "$username:$password" | chpasswd -c SHA512 #change password and encrypt with sha512 algorithm
  13. echo "$username:x:$var" >> /etc/group #store group id number
  14. cd /home #go to home directory
  15. mkdir $username #create a folder dedicated to the user inside home directory
  16. chmod 700 /home/$username # set owner permission to rwx whereas group and public to be no access
  17. chown -R $username /home/$username #change the ownership to newly created user
  18. echo "The user has been successuflly created"
  19. else
  20. echo "THIS SCRIPT CAN ONLY BE USED BY THE ROOT USER."
  21. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top