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.

63 lines
1.4 KiB

9 years ago
9 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=22
  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. set -x
  25. # white list ssh access
  26. for ip in "${WHITELIST[@]}"; do
  27. ufw allow from $ip to any port $SSH_PORT
  28. done
  29. if [ ${#WHITELIST[@]} -eq 0 ]; then
  30. ufw allow $SSH_PORT
  31. fi
  32. # open ports
  33. for port in "${OPEN_PORTS[@]}"; do
  34. ufw allow $port
  35. done
  36. # apply
  37. ufw --force enable
  38. set +x
  39. # set up firewall END
  40. # watch the logs and have them emailed to me
  41. # apt-get install -y logwatch
  42. # echo "/usr/sbin/logwatch --output mail --mailto $ADMIN_EMAIL --detail high" >> /etc/cron.daily/00logwatch
  43. # set up user account
  44. echo "CREATE USER $USER ..."
  45. useradd $USER -d /home/$USER
  46. # This user should not have root access.
  47. # usermod -aG sudo $USER
  48. mkdir /home/$USER
  49. cp /etc/skel/.bashrc .
  50. cp /etc/skel/.profile .
  51. chown -R $USER:$USER /home/$USER
  52. echo "Done setting env. Switching to $USER..."
  53. su $USER