cd ..
root@paste:~/pG-wcNtm6$cat paste
paste://pG-wcNtm6PUBLIC
public paste

setup-fail2ban-ssh.sh

β€”135 views835 chars

stdout

Paste content

>_bashauto-detected
#!/bin/bash

echo "πŸ” Installing Fail2Ban..."
sudo apt update
sudo apt install -y fail2ban

echo "πŸ› οΈ Configuring SSH jail with 1 year ban..."
# Backup config if needed
if [ ! -f /etc/fail2ban/jail.local.bak ]; then
    sudo cp /etc/fail2ban/jail.local /etc/fail2ban/jail.local.bak 2>/dev/null
fi

# Create jail.local if doesn't exist
if [ ! -f /etc/fail2ban/jail.local ]; then
    sudo touch /etc/fail2ban/jail.local
fi

# Write SSH jail config for 1 year ban
sudo bash -c 'cat > /etc/fail2ban/jail.local <<EOF
[sshd]
enabled = true
port    = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
maxretry = 5
findtime = 10m
bantime  = 31536000
EOF'

echo "πŸ” Restarting Fail2Ban..."
sudo systemctl restart fail2ban

echo "βœ… Fail2Ban configured with 1-year SSH ban."
sudo fail2ban-client status sshd

$ tail -f comments.log

Comments [0]

// no comments yet