You can prevent brute force attacks up to a certain point. For that, there are several things you need to keep in mind. For example, you need to use a very strong password, limit failed login attempts, protect your Root account, change the port, enable CAPTCHA, etc. Apart from that, you can also use two-factor authentication to add an additional layer of security.