user.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. echo -e '\033[35m
  3. __ _______ __________
  4. / / / / ___// ____/ __ \
  5. / / / /\__ \/ __/ / /_/ /
  6. / /_/ /___/ / /___/ _, _/
  7. \____//____/_____/_/ |_|
  8. \033[0m'
  9. echo -e "\033[35;1mCreate new user (you will be asked a user name and a password) \033[0m"
  10. if [ "$EUID" -ne 0 ]; then
  11. echo "Please run as root"
  12. exit
  13. fi
  14. sleep 3
  15. echo -n "Enter user name: "
  16. read user
  17. while [ "$user" = "" ]
  18. do
  19. read -p "enter a user name ? " user
  20. if [ "$user" != "" ]; then
  21. # check if user already exists
  22. if id "$user" >/dev/null 2>&1; then
  23. echo "user $user alreday exists, you must provide a non existing user name."
  24. user=""
  25. else
  26. read -p "is user name $user correcte [y|n] " validated
  27. if [ "$validated" = "y" ]; then
  28. break
  29. else
  30. user=""
  31. fi
  32. fi
  33. fi
  34. done
  35. adduser "$user"
  36. echo "adding $user to admin group and limiting su to the admin group"
  37. groupadd admin
  38. usermod -a -G admin "$user"
  39. # allow admin group to su
  40. dpkg-statoverride --update --add root admin 4750 /bin/su
  41. echo -e "\033[92;1muser $user configured\033[Om"