Firewall is a popular way of protecting servers. It is used to control which network traffic to pass to and from the server. Typically, all incoming ports to the server are blocked except for a few that servers the public. Like port 80 if our server is a web server.
The most common attack to servers is to brute force guess your password. An effective way to counter this is to disable login via username password. An alternative way to login after doing that isto use ssh key pair login.