Firstly a lot of people work on Ubuntu in their free time (many of them programming, but also those of here for instance answering people's questions). Also some people donate to Ubuntu.
However there is more to the story. Canonical Ltd. is a private company that created and continues to pay for Ubuntu. We know Canonical hadn't been making a profit, but Canonical was initially founded by multi-millionaire Mark Shuttleworth which meant it didn't have to focus on making money right away.
However Canonical is now looking towards to making Ubuntu profitable. (After all, they have 600+ employees to pay every month!) There are some indications this has been successful. Their key revenue streams offer services around Ubuntu:
- Support services (mostly to business) alongside which they sell Landscape
- Contracting services to businesses (for instance working with OEMs such as Dell, or helping Google with Chrome OS). As Ubuntu makes its way onto mobile phones and TVs then this will grow.
- Ubuntu Software Centre's paid section (Canonical takes a cut of purchases)
- The Canonical Store (selling physical Ubuntu branded items)
- Closed-source projects wishing to use Launchpad.net can purchase a license
Ubuntu One (online file storage and synchronization service) and Music Store (selling music from within Ubuntu) - discontinued.
- Amazon referrals. When you search the Ubuntu Dash, you may see Amazon products (unless you have turned it off). Ubuntu takes a cut of these.[reference wouldn't hurt]
All of these are areas that Canonical hopes will grow.