diff --git a/init-linux-harden.sh b/init-linux-harden.sh index fb9ec94..867a81b 100644 --- a/init-linux-harden.sh +++ b/init-linux-harden.sh @@ -11,7 +11,8 @@ # OVH # Hetzner - +# TODO - fail2ban does not work on Ubuntu 14.04 => does NOT read the defaults-debian.conf file + # => Check what makes debian read it => something in fail2ban.conf file SCRIPT_NAME=server_harden SCRIPT_VERSION=0.2 @@ -187,6 +188,7 @@ cat < AuthorizedKeysFile '%h\/\.ssh\/authorized_keys'" - systemctl restart sshd + { + service sshd restart 2>> "$LOGFILE" >&2 + } || { + # Because Ubuntu 14.04 does not have sshd + service ssh restart 2>> "$LOGFILE" >&2 + } + set_op_code $? } 2>> "$LOGFILE" >&2 if [[ $OP_CODE -eq 0 ]]; then @@ -1036,7 +1050,7 @@ op_log "${OP_TEXT[5]}" { apt-get update apt-get upgrade -y - apt-get install -y sudo systemd curl screen ufw fail2ban + apt-get install -y sudo curl screen ufw fail2ban set_op_code $? } 2>> "$LOGFILE" >&2 @@ -1116,8 +1130,9 @@ if [[ $InstallReqSoftwares -eq 2 ]]; then sed -ri "/^\[DEFAULT\]$/,/^# JAILS$/ s/^backend[[:blank:]]*=.*/backend = polling/" /etc/fail2ban/jail.local sed -ri "/^\[DEFAULT\]$/,/^# JAILS$/ s/^ignoreip[[:blank:]]*=.*/ignoreip = 127.0.0.1\/8 ::1 ${pub_ip}/" /etc/fail2ban/jail.local - # TODO - Below - make it usable for Ubuntu as well - cp /etc/fail2ban/jail.d/defaults-debian.conf /etc/fail2ban/jail.d/defaults-debian.conf"$BACKUP_EXTENSION" + if [[ -f /etc/fail2ban/jail.d/defaults-debian.conf ]]; then + cp /etc/fail2ban/jail.d/defaults-debian.conf /etc/fail2ban/jail.d/defaults-debian.conf"$BACKUP_EXTENSION" + fi cat < /etc/fail2ban/jail.d/defaults-debian.conf [sshd] @@ -1139,7 +1154,7 @@ FAIL2BAN set_op_code $? - systemctl restart fail2ban + service fail2ban start set_op_code $? } 2>> "$LOGFILE" >&2