I think changing the port blocks them for a little bit until they scan all my ports again. They found me at 2222, so I had to change again. They were using up about 8-10GB of bandwidth per month just on SSH login attempts.
Bonus bandwidth usage: https://i.imgur.com/T0sJCpM.png
Seems like 1-2GB per day sometimes, hah.
Then I have a bastion server with Teleport to access the servers when I'm not on an allowed network. I could have used Tailscale or OpenVPN or even OpenSSH again, but I went with Teleport. Mostly because it also supports Kubernetes well and does user management and MFA nicely.
I also, for fun, did setup a GeoIP firewall on the bastion. It uses iptables and xtable-addons and a maxmind database. I blocked many countries that are known do such login attempts. I of course blocked myself out of the bastion during the setup of the GeoIP firewall.
Maybe leave a honeypot/tarpit server on the original ssh port to distract the bots.
8gb of bandwidth a month seems not worth sweating about.
- Ensure you have SSH key trusts and then disable password authentication and don't bother blocking anyone. It's just noise and the C&C nodes will just use a different node to reach you.
- If the noise is distracting, move the sshd listener to a high port. This is not security and will not stop a targeted attack, this is just to stop the noise. 99.999% of the bots will just go away. [2] Ensure the port you select is opened on the firewall first.
- Optionally, add CIDR/IP restrictions to your SSH keys if you are concerned that you might leak your private keys somehow. This is done on the server side in the authorized keys file(s) depending on how you configured key trusts. Maybe leave one low-permission account unrestricted in the event you want to access from a cell phone.
grep -i authorized /etc/ssh/sshd_config
AuthorizedKeysFile /etc/ssh/keys/%u
cat /etc/ssh/keys/bender
from="172.16.0.0/12,192.168.0.0/16" ssh-rsa AAAA[snip]... comment
- Very optionally, only permit connections to ssh that have valid MSS. This drops massscan, the most prevalent scanner used by bots. If your clients use jumbo-frames then you may need different values such as 1280:9200. Most home connections will be 1460 and some mobile ipv6ipv4 gateways are 1280 or 1380. Adjust as you see fit after using tcpdump to see valid values vs. bot values. # see what is valid and invalid by capturing syn packets to 22
tcpdump -p -i any -NNnnt -c512 port 22 and 'tcp[13] == 2'
# limit ssh to a desired mss range.
-A INPUT -m tcp -p tcp --dport 22 --syn -m tcpmss --mss 1280:1460 -j ACCEPT
[1] - https://www.ssh-audit.com/[2] - My anecdotal experience since the 1990's.
https://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server...
You’ll end up moving around the point where probes happen if you have a bastion, if you use tail scale, if you run fail2ban, move the service to another port, implement knocking or any other overused suggestion.
The only real solution is either keeping your sshd up-to-date to minimize the risk of zerodays, moving it to a private address (and by virtue of still needing to get to it, exposing yet another service), filtering everything but a handful of addresses or just not using it.
How much time do you want to sink into this, what’s your threat model, is that used bandwidth actually worth anything are the big questions I’d ask right away to inform an answer.
Do geoblocking. Block all of China, Russia, and North & South Korea. 90% of hacking attempts come from these areas.
If you change MAC, the provider will assign new IP-address. And then you use different port every day. Port will be day number plus X, which easy to remember and easy to automate.