Companies such as videolan, Mozilla, canonical ,etc make open source software. These companies have programmers as employees and they have other expenses such as server maintainance, still they are not in loss. How they make money?
One way is through donations.
Mozilla and Opera get cash from google for the search tab. Almost all of them should have adverts. People aren't really generous enough to make an institution survive on donations.
Donations, advertisements, corporate deals(create customized version of the software for the company), and since its open source most of the work is done by volunteers, so most companies keep a small number of employees for final validation etc, debugging is almost exclusively done by volunteers and users.
companies like red hat and novell earn huge profits from providing service support and solutions.