You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

10 years ago
10 years ago
10 years ago
  1. #!/bin/bash
  2. # Run this as root user
  3. # This part is for hardening the server and setting up a user account
  4. if [ `whoami` != "root" ];
  5. then
  6. echo "You must run this script as root"
  7. exit 1
  8. fi
  9. USER="tmuser"
  10. OPEN_PORTS=(46656 46657 46658 46659 46660 46661 46662 46663 46664 46665 46666 46667 46668 46669 46670 46671)
  11. SSH_PORT=20
  12. WHITELIST=()
  13. # update and upgrade
  14. apt-get update -y
  15. apt-get upgrade -y
  16. # fail2ban for monitoring logins
  17. apt-get install -y fail2ban
  18. # set up the network time daemon
  19. apt-get install -y ntp
  20. # install dependencies
  21. apt-get install -y make screen gcc git mercurial libc6-dev pkg-config libgmp-dev
  22. # set up firewall
  23. echo "ENABLE FIREWALL ..."
  24. # white list ssh access
  25. for ip in "${WHITELIST[@]}"; do
  26. ufw allow from $ip to any port $SSH_PORT
  27. done
  28. if [ ${#WHITELIST[@]} -eq 0 ]; then
  29. ufw allow $SSH_PORT
  30. fi
  31. # open ports
  32. for port in "${OPEN_PORTS[@]}"; do
  33. ufw allow $port
  34. done
  35. # apply
  36. ufw enable
  37. # watch the logs and have them emailed to me
  38. # apt-get install -y logwatch
  39. # echo "/usr/sbin/logwatch --output mail --mailto $ADMIN_EMAIL --detail high" >> /etc/cron.daily/00logwatch
  40. # set up user account
  41. echo "CREATE USER $USER ..."
  42. useradd $USER -d /home/$USER
  43. # This user should not have root access.
  44. # usermod -aG sudo $USER
  45. mkdir /home/$USER
  46. cp /etc/skel/.bashrc .
  47. cp /etc/skel/.profile .
  48. chown -R $USER:$USER /home/$USER
  49. echo "Done setting env. Switching to $USER..."
  50. su $USER