While fail2ban is very useful you still get a lot of automated authentication attempts. I additionally added port knocking using the knock daemon on the Server: so in regular state even the ssh port is blocked by the firewall. to temporarily unlock the ssh port you have to knock on a few ports in a configurable order. only then the ssh port is opened for a few seconds foryou to connect to. e.g. knock youserver.com 18754 26557 28864 && ssh user@yourserver.com to login
this completely took away the failed login attempts in my logs.
I have 17 years of experience as a Full Stack Developer. I like how Python is robust and JavaScript is ambitious. Sometimes I dream in my mind about the wind in my sail...
Native Android developer/Consultant for Appwise, I work on custom projects for clients.
PHP/JS (web) developer in my freetime. Trying to keep learning in an ever changing tech world.
Great post! This is also my default workflow when I setup a new VPS.
Just a couple of tips:
Just like SSH has an alternative syntax you can do the same for port 80 and 443. ufw allow http & ufw allow https
You can also run the command: ufw app list
This will show a list of available applications that you can add to your UFW firewall so that if the port config has changed for example this will also be updated in your UFW.
My UFW rules:
To Action From
-- ------ ----
Nginx Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Nginx Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)
If you want your server to accept IPv6 you will need to enable this in your UFW config.
sudo nano /etc/default/ufw
And then change this: IPV6=yes
UFW reboot required after this change of course.
For fail2ban I have 3 jails enabled: sshd, sshd-ddos and nginx-botsearch
Current status for my sshd jail:
Status for the jail: sshd
|- Filter
| |- Currently failed: 2
| |- Total failed: 28259
| `- File list: /var/log/auth.log
`- Actions
|- Currently banned: 0
|- Total banned: 78
`- Banned IP list:
I have 17 years of experience as a Full Stack Developer. I like how Python is robust and JavaScript is ambitious. Sometimes I dream in my mind about the wind in my sail...
It feels really strange that neither the article nor anyone in the comments mention one of the most important thing:
Keep your software up to date
You can devise a firewall as hard to open as the most sophisticated safe, but if the back of the safe is missing, you did nothing. Security vulnerabilities happen, not just in the applications you use, but even in the operating system. Keep everything up to date, and you are one step closer to being protected.
I have 17 years of experience as a Full Stack Developer. I like how Python is robust and JavaScript is ambitious. Sometimes I dream in my mind about the wind in my sail...
I have 17 years of experience as a Full Stack Developer. I like how Python is robust and JavaScript is ambitious. Sometimes I dream in my mind about the wind in my sail...
I have 17 years of experience as a Full Stack Developer. I like how Python is robust and JavaScript is ambitious. Sometimes I dream in my mind about the wind in my sail...
I set up a weak root password (it was the same as I used to have on my local PC) and forgot to close password access to the server in /etc/ssh/sshd_config.
We're a place where coders share, stay up-to-date and grow their careers.
While fail2ban is very useful you still get a lot of automated authentication attempts. I additionally added port knocking using the knock daemon on the Server: so in regular state even the ssh port is blocked by the firewall. to temporarily unlock the ssh port you have to knock on a few ports in a configurable order. only then the ssh port is opened for a few seconds foryou to connect to. e.g.
knock youserver.com 18754 26557 28864 && ssh user@yourserver.comto loginthis completely took away the failed login attempts in my logs.
Thank you for
knockutility. Never used it before.Great post! This is also my default workflow when I setup a new VPS.
Just a couple of tips:
Just like SSH has an alternative syntax you can do the same for port 80 and 443.
ufw allow http&ufw allow httpsYou can also run the command:
ufw app listThis will show a list of available applications that you can add to your UFW firewall so that if the port config has changed for example this will also be updated in your UFW.
My UFW rules:
If you want your server to accept IPv6 you will need to enable this in your UFW config.
And then change this:
IPV6=yesUFW reboot required after this change of course.
For fail2ban I have 3 jails enabled:
sshd,sshd-ddosandnginx-botsearchCurrent status for my
sshdjail:Thanks to you, I pay attention to
sshd-ddos!In front of the nginx on my server I have traefik inside the docker container. I will try to research how to make them work together.
It feels really strange that neither the article nor anyone in the comments mention one of the most important thing:
Keep your software up to date
You can devise a firewall as hard to open as the most sophisticated safe, but if the back of the safe is missing, you did nothing. Security vulnerabilities happen, not just in the applications you use, but even in the operating system. Keep everything up to date, and you are one step closer to being protected.
Completely agree with your advice. I forgot to mention it in the article, I changed the post with your advice. Thank you!
Hi,
I hope to get your consent to translate and shared with Chinese developers, I will indicate the source and author.
Surely, you can do it!
Chinese link:nextfe.com/protect-server-from-hac... (中文)
Thanks!
Great post!
Thanks for sharing.
Thank you !
Great post! Really needed!
I set up a weak root password (it was the same as I used to have on my local PC) and forgot to close password access to the server in /etc/ssh/sshd_config.