install-debian-server.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. # bachir soussi chiadmi
  3. #
  4. # http://www.debian.org/doc/manuals/securing-debian-howto/
  5. # https://www.thefanclub.co.za/how-to/how-secure-ubuntu-1204-lts-server-part-1-basics
  6. # https://www.linode.com/docs/websites/lamp/lamp-server-on-debian-7-wheezy/
  7. #
  8. echo "This script has been tested only on Linux Debian 7"
  9. echo "Installing harden"
  10. apt-get install harden
  11. echo "Installing ufw and setup firewall (allowing only ssh and http)"
  12. apt-get install ufw
  13. ufw allow ssh
  14. ufw allow http
  15. ufw enable
  16. ufw status verbose
  17. echo "Create new user (you will be asked a user name and a password)"
  18. read -p "Enter user name: " user
  19. # read -p "Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
  20. adduser "$user"
  21. echo "adding $user to admin group and limiting su to the admin group"
  22. groupadd admin
  23. usermod -a -G admin "$user"
  24. dpkg-statoverride --update --add root admin 4750 /bin/su
  25. echo "Securing ssh (disabling root login)"
  26. sed -i 's/PermitRootLogin\ yes/PermitRootLogin no/g' /etc/ssh/sshd_config
  27. sed -i 's/PermitEmptyPasswords\ yes/PermitEmptyPasswords no/g' /etc/ssh/sshd_config
  28. sed -i 's/Protocol\ [0-9]/Protocol 2/g' /etc/ssh/sshd_config
  29. echo "Installing AMP web server"
  30. echo "Installing Apache2"
  31. apt-get install apache2
  32. a2enmod rewrite
  33. service apache2 restart
  34. echo "installing Mysql"
  35. apt-get install mysql-server
  36. mysql_secure_installation
  37. echo "Installing PHP"
  38. apt-get install php5 php-pear
  39. echo "Configuring PHP"
  40. cp /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.back
  41. sed -i "s/max_execution_time\ =\ [0-9]\+/max_execution_time = 60/g" /etc/php5/apache2/php.ini
  42. sed -i "s/max_input_time\ =\ [0-9]\+/max_input_time = 60/g" /etc/php5/apache2/php.ini
  43. sed -i "s/memory_limit\ =\ [0-9]\+M/memory_limit = 512M/g" /etc/php5/apache2/php.ini
  44. sed -i "s/;\?error_reporting\ =\ [^\n]\+/error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR/g" /etc/php5/apache2/php.ini
  45. sed -i "s/;\?display_errors\ =\ On/display_errors = Off/g" /etc/php5/apache2/php.ini
  46. sed -i "s/;\?log_errors\ =\ Off/log_errors = On/g" /etc/php5/apache2/php.ini
  47. # following command doesn't work, make teh change manualy
  48. #sed -ri ":a;$!{N;ba};s/;\?\ \?error_log\ =\ [^\n]\+([^\n]*\n(\n|$))/error_log = \/var\/log\/php\/error.log\1/g" /etc/php5/apache2/php.ini
  49. echo "register_globals = Off" >> /etc/php5/apache2/php.ini
  50. mkdir /var/log/php
  51. chown www-data /var/log/php
  52. apt-get install php5-mysql
  53. service apache2 restart