How do I prevent compromises from happening?
There is no solution that will provide perfect security for your server. Software such as the OS and stack running on your server sometimes contains flaws that can allow for bad actors to enter and abuse an otherwise legitimate system. It's also not always practical to lock everything down completely as that can unintentionally restrict legitimate access to services. To best protect your system against compromises, it's recommended to take an active approach to your server's security.
I recommend that you start by checking out the advice in this post. The first response to that post contains a handful of links that will help get you setup with basic security protections for your Linode. You can also find instructions there on how to deal with a compromise if it's already happened.
From there, it's necessary to consider your entire software stack and its features, focusing particularly on which features you do and do not need. Anything that's not being used should be de-activated/uninstalled, while anything that is being used should be secured in such a way that leaves it accessible to legitimate users. This is not always the simplest process, and may require contracting a professional if it's not something you're comfortable doing on your own.