Advertisement
Sweetening

My harden script for debian

Mar 19th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Enable automatic security updates
  4. sudo apt-get install -y unattended-upgrades
  5. sudo dpkg-reconfigure -plow unattended-upgrades
  6.  
  7. # Firewall configuration (UFW)
  8. sudo apt-get install -y ufw
  9. sudo ufw default deny incoming
  10. sudo ufw default allow outgoing
  11. sudo ufw allow ssh
  12. sudo ufw enable
  13.  
  14. # Install and configure Fail2Ban
  15. sudo apt-get install -y fail2ban
  16. sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
  17. sudo systemctl restart fail2ban
  18.  
  19. # Enable and configure a strong password policy
  20. sudo apt-get install -y libpam-cracklib
  21. sudo cp /etc/pam.d/common-password /etc/pam.d/common-password.backup
  22. echo "password requisite pam_cracklib.so retry=3 minlen=10 difok=3 ucredit=-1 dcredit=-1 ocredit=-1 lcredit=-1" | sudo tee -a /etc/pam.d/common-password
  23.  
  24. # Secure SSH configuration
  25. sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config
  26. sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
  27. sudo systemctl restart ssh
  28.  
  29. # Set up automatic security checks with Lynis
  30. sudo apt-get install -y lynis
  31. sudo lynis audit system
  32.  
  33. # Enable automatic updates for other software packages
  34. sudo apt-get install -y unattended-upgrades
  35. sudo dpkg-reconfigure -plow unattended-upgrades
  36.  
  37. # Install and configure a basic intrusion detection system (AIDE)
  38. sudo apt-get install -y aide
  39. sudo aideinit
  40.  
  41. # Harden user accounts and privileges
  42. # (Review each change carefully, as it may affect your specific use case)
  43. # Example: Lock accounts without passwords
  44. # sudo passwd -l <username>
  45.  
  46. # Disable unnecessary services
  47. # (Review each service and disable if not needed)
  48. # Example: sudo systemctl disable <service-name>
  49.  
  50. # Monitor system logs for suspicious activity
  51. # (Implement log monitoring solutions based on your specific requirements)
  52.  
  53. # Regularly update and patch the system
  54. sudo apt-get update && sudo apt-get upgrade -y
  55.  
  56. echo "Hardening complete. Please review each change to ensure it aligns with your requirements."
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement