Skip to content

Instantly share code, notes, and snippets.

@faizalmansor
Created April 18, 2019 06:15
Show Gist options
  • Save faizalmansor/6881991f717e69e12a20cd21c685d95e to your computer and use it in GitHub Desktop.
Save faizalmansor/6881991f717e69e12a20cd21c685d95e to your computer and use it in GitHub Desktop.
BASH Script to automate fail2ban installation and configuration on Centos 7
#!/bin/bash
# Script : ost-oassi-centos7.sh
# Author : Osh <faizal@myopensoft.net>
# Title : Osh Automated Server Security Installer
# Description: Script to automate installation & configuration of fail2ban
# Target OS : Centos 7
echo "Start Osh Automated Server Security Installer..."
# Install epel-release if not yet installed
yum install -y epel-release
# Install security softwares
yum install -y fail2ban fail2ban-systemd
# Update selinux policy
yum update -y selinux-policy*
# Copy fail2ban jail configuration file to local configuration file
cp -pf /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
# Create fail2ban sshd configuration file
cat > /etc/fail2ban/jail.d/sshd.local << EOL
[sshd]
enabled = true
port = ssh
#action = firewallcmd-ipset
logpath = %(sshd_log)s
maxretry = 5
bantime = 86400
EOL
# Add firewalld on startup & start firewalld
systemctl enable firewalld
systemctl start firewalld
# Add fail2ban on startup & start fail2ban
systemctl enable fail2ban
systemctl start fail2ban
echo "Completed OASSI"
@faizalmansor
Copy link
Author

Do
chmod +x ost-oassi-centos7.sh
before running the script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment