Created
February 5, 2023 16:13
-
-
Save maikgreubel/e1a101932ca828a6f52eed06d55713c0 to your computer and use it in GitHub Desktop.
harden-sshd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $UID -ne 0 ]; then | |
echo "root only" | |
exit 1 | |
fi | |
restart=0 | |
for i in $(grep "Failed password" /var/log/secure | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | uniq) | |
do | |
if [ `grep -c " $i\$" /etc/hosts.deny` -eq 0 ]; then | |
echo "sshd: $i" >> /etc/hosts.deny | |
echo "Added $i" | |
restart=1 | |
fi | |
done | |
if [ $restart -gt 0 ]; then | |
service sshd restart | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment