Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/bin/bash
  2. ROOT_UID=0
  3. SUCCESS=0
  4. E_USEREXISTS=70
  5.  
  6. # Run as root, of course. (this might not be necessary, because we have to run the script somehow with root anyway)
  7. if [ "$UID" -ne "$ROOT_UID" ]
  8. then
  9. echo "Must be root to run this script."
  10. exit $E_NOTROOT
  11. fi
  12.  
  13. #test, if both argument are there
  14. if [ $# -eq 2 ]; then
  15. username=$1
  16. pass=$2
  17.  
  18. # Check if user already exists.
  19. grep -q "$username" /etc/passwd
  20. if [ $? -eq $SUCCESS ]
  21. then
  22. echo "User $username does already exist."
  23. echo "please chose another username."
  24. exit $E_USEREXISTS
  25. fi
  26.  
  27. #Preerequisite for mkpasswd : whois
  28.  
  29. useradd -p `mkpasswd "$pass"` -d /home/"$username" -m -g users -s /bin/bash "$username"
  30. #Allow no one else to access the home directory of the user
  31. chmod 750 /home/"$username"
  32. echo "the account is setup"
  33.  
  34. else
  35. echo " Expected usage: ./autoadder username password"
  36. fi
  37.  
  38. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement