Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # 1) copy this file to target server (you may just use `nano` editor)
  4. # 2) run as ` script-name username password` (starting with space symbol to prevent writing password to bash commands history)
  5. ROOT_UID=0
  6. SUCCESS=0
  7. E_USEREXISTS=70
  8. E_NOTROOT=67
  9.  
  10. # Run as root, of course. (this might not be necessary, because we have to run the script somehow with root anyway)
  11. if [ "$UID" -ne "$ROOT_UID" ]
  12. then
  13. echo "Must be root to run this script."
  14. exit $E_NOTROOT
  15. fi
  16.  
  17. #test, if both argument are there
  18. if [ $# -eq 2 ]; then
  19. username=$1
  20. pass=$2
  21.  
  22. # Check if user already exists.
  23. grep -q "$username" /etc/passwd
  24. if [ $? -eq $SUCCESS ]
  25. then
  26. echo "User $username does already exist."
  27. echo "please chose another username."
  28. exit $E_USEREXISTS
  29. fi
  30.  
  31. apt install whois
  32. # useradd -p `mkpasswd "$pass"` -d /home/"$username" -m -g users -s /bin/bash "$username"
  33. useradd -p `mkpasswd "$pass"` -d "/home/$username" -m -s /bin/bash "$username"
  34.  
  35.  
  36. echo "$username ALL=(ALL:ALL) ALL" >> /etc/sudoers
  37.  
  38. echo "the account was setup"
  39.  
  40. else
  41. echo " this script needs 2 arguments you have given $# "
  42. echo " you have to call the script $0 username and the pass "
  43. fi
  44.  
  45. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement