Based of https://www.axllent.org/docs/ssh-geoip/ i've created/modified a script to block all SSH Login Attempts not from a Whitelist OR whitelist Country. Tested on Debian. If there is no geoiplookup, cou can modify the script to whatveer lookuptool you have.
Installation:
- Download Script:
wget https://raw.githubusercontent.com/dMopp/ssh-geoblock/main/sshCountryFilter.sh
- Modify Script. (Modify Whitelist, Separated by Space, Modify Country Whitelist)
- install geoip:
apt install geoip-database geoip-bin
- Test script:
sshCountryFilter.sh <addIPhere>
- ATTENTION: If you did something wrong, you need local/KVM access to the VM to repair
- Modify
/etc/hosts.deny
--> addsshd: ALL
- Modify
/etc/hosts.allow
--> addsshd: ALL: aclexec /path/to/sshCountryFilter.sh %a
- ATTENTION: Keep current SSH session open and TEST if you can connect!!
- If yes --> you can close the connection