Not a snippet, more a serious advice:
Just playing with my VPS-Server in prod and I mentioned tons of login tries from guys trying to get access to the root account.
My provider (IONOS, ex 1and1/1und1) offers a console where you can switch off ports by default (like a firewall before the server). So I switch off port 22 when I'm not accessing the server via SSH or FTP. Very comfortable and safe.
Of course there are other ways which then needs reconfoguration the server itsself (here you could damage your installation or lock yourself out).
Just playing with my VPS-Server in prod and I mentioned tons of login tries from guys trying to get access to the root account.
My provider (IONOS, ex 1and1/1und1) offers a console where you can switch off ports by default (like a firewall before the server). So I switch off port 22 when I'm not accessing the server via SSH or FTP. Very comfortable and safe.
Of course there are other ways which then needs reconfoguration the server itsself (here you could damage your installation or lock yourself out).