Skip to content

Instantly share code, notes, and snippets.

@kylekeesling
Created November 18, 2024 20:30
Show Gist options
  • Save kylekeesling/593f8d360c7de57e23e2bce128223971 to your computer and use it in GitHub Desktop.
Save kylekeesling/593f8d360c7de57e23e2bce128223971 to your computer and use it in GitHub Desktop.
server-protection-scripts
# disable SSH sessions using passwords
sudo nano /etc/ssh/sshd_config
```
PasswordAuthentication no
PubkeyAuthentication yes
```
sudo systemctl restart ssh
# Enable Uncomplicated Firewall (ufw) and only allow access via SSH and SSL/TLS
apt-get install ufw
ufw allow 'OpenSSH'
ufw allow 443
ufw allow 80
ufw enable
# Enable fail2ban
apt install fail2ban
nano /etc/fail2ban/jail.local
```
[sshd]
enabled = true
port = 22
logpath = /var/log/auth.log
maxretry = 5
bantime = 600
```
systemctl start fail2ban
systemctl enable fail2ban
fail2ban-client status sshd
# enabled Ubuntu unattended updates
sudo apt update
sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment