Its simple, you use somthing like the Affero license so no one can make changes that you can't access. Since anyone can try, whatever good ideas other people have you can re-incorporate, so you can potentially have a far bigger unpaid developer base. If your product is known to attract hacker types as customers, they can act as force multipliers, easily. As compared to a closed program, you'll have more eyes on the code. Its also your code, and you know it better than anyone else.
Then you simply focus on having the best quality of service. You can copy software, you can't copy quality of service.
Combine these two, its not as easy as you think to compete against someone else with their own software.
You also have your brand name and reputation. which is built on that quality of service. Despite the fact that CentOS is given away for free, people pay good money for RHEL subscriptions, and RH is an economicly viable company.
The support is where the money is. The actual product is a loss leader.