Skip to content

Instantly share code, notes, and snippets.

@jeffrade
Created June 30, 2019 14:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffrade/fbeb78594ae3459b44b4216043a25595 to your computer and use it in GitHub Desktop.
Save jeffrade/fbeb78594ae3459b44b4216043a25595 to your computer and use it in GitHub Desktop.
Install fail2ban on Debian Linux
#!/bin/sh -x
echo "Starting..."
apt-get install -y fail2ban
systemctl start fail2ban
systemctl enable fail2ban
> /etc/fail2ban/jail.local
echo "[sshd]" >> /etc/fail2ban/jail.local
echo "enabled = true" >> /etc/fail2ban/jail.local
echo "port = 22" >> /etc/fail2ban/jail.local
echo "filter = sshd" >> /etc/fail2ban/jail.local
echo "logpath = /var/log/auth.log" >> /etc/fail2ban/jail.local
echo "maxretry = 3" >> /etc/fail2ban/jail.local
systemctl restart fail2ban
rm -rf $HOME/.ssh
mkdir $HOME/.ssh && echo "" >> $HOME/.ssh/authorized_keys
chmod go-w $HOME $HOME/.ssh
chmod 600 $HOME/.ssh/authorized_keys
chown `whoami` $HOME/.ssh/authorized_keys
# Use ssh-copy-id to add .ssh/id_rsa.pub from
# client machine to remote server https://linux.die.net/man/1/ssh-copy-id
echo "Done!"
@jeffrade
Copy link
Author

This script now has a home at https://github.com/jeffrade/proxy-server

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