If you're using Digital Ocean, you can set a firewall rule via the droplet web interface, that's quick to do. Otherwise just a simple iptables does the trick.
Edit: if you have a static public IP, of course
Using an alternative connection to activate the protocol is probably the only reasonable defense:
* An https service that can enable a port for connections from an IP for a limited time (which has some security implications too since it would need root access, or to trigger something with root access)
* Something built into KLO hardware, or software provided by your provider (including something simple like turn on the firewall a few minutes after boot, and using the reboot trigger and connecting in that brief window.. as long as you don't mind your server down - probably ok as an emergency recovery strategy)
* Some form of port knocking
Variable port knocking ie a different sequence tied to rules can help expose compromised networks making up the internet. Say you port knock from your mobile phone, use one port knocking sequence, if port knocking from a different internet connection use a different port knocking sequence. This can help highlight those networks with taps, but the identity of who is behind the tap can still remain a mystery, unless you set other traps. You also need to trust your devices, which no one can legally do as copyright prevents people from examining the code on their chips and some OS'es like Windows. NSA still provide the tools for examining code for free https://www.nsa.gov/resources/everyone/ghidra/ but as always Resource Burning is something to take seriously when trying to secure your systems. Sometimes its best to view servers as disposable, so automation can be your friend even simple PXE boots can be useful. Its also worth noting you can run at least two different ADSL connections down the same copper wire, they do here in the UK at least, most people dont know this, but the TV & film streaming services use this, some ISP supplied routers can give this away if you examine the backup config files.
What I’m envisaging is: I pay somebody, make an account on their site and add 2FA, and then they give me a server with a static IP and handle the auth. Then all I have to do is to whitelist that static IP.
Ideally it would function as both an HTTP proxy and an SSH proxy; like a ‘secure web portal’
They have a cloud offering in beta where they'll manage the proxy/bastion.
I tie the Pi to my home router via OpenVPN and use https://freedns.afraid.org/ for dynamic DNS to send calls to. It has worked fine for four years now. The Pi runs a one liner from a cronjob every 15 mins or so. The TTL for the DNS entry is very short and the DHCP lease is something like 24 hours plus also I think it tends to renew the last one used reasonably reliably. I don't bother monitoring that. I could write the cronjob result to a local log I suppose.
More things can go wrong than the tiny window that might exist when the DNS might be out of whack. Don't let the lack of a static IP address get in the way.
We also use bastion hosts. They're whitelisted for key-based SSH only access for our public IP addresses. We can jump around to other servers once we login to that one, but our externally facing servers never advertise anything other their base service (:443 or whatever is running on them).
I also use them with my personal servers and just leave them shut off when I'm not actively using them. This keeps costs down, but more importantly it permanently blocks off SSH access unless I'm specifically in need of it.
PAM modules also help.
Obscure port does nothing.. it eventually finds it and then you'll see tons of servers try that port (unless you constantly move it).
I'm not sure how you imagine Pluggable Authentication Modules would help? Fail2Ban or some sort of active IPS helps, but because the IPs are very varied (and presumably ever increasing) and infrequently re-attempt it doesn't help much.
Note anyone running exposed SSH without keys or certs, should run the detection script[0] (which is just shell and you should read first before installing) provided by Guardicore
[0]: https://github.com/guardicore/labs_campaigns/tree/master/Fri...
I thought about using fail2ban but every login is a different IP (using my eyeballs, I didn't parse the logs).
You do not need to use firewalld, either, although this does. See the second link for something generic ([2]).
[1] https://pagure.io/firewalld-blacklist/tree/master
[2] https://www.linuxjournal.com/content/advanced-firewall-confi...
- Always use keys and disable password based login
- Do not have ssh publicly exposed, or at the very least only via a bastion server, but if that bastion server is publicly available, then you are still quite vulnerable (perhaps even more so if someone gets into your bastion and is able to ssh to all the things if you are using key-based logins from the bastion)
- Always use a passphrase for your keys (helps with the “if someone breaks into your bastion scenario”)... but the best thing you can do is just don’t expose ssh to the public network