How to earn money through open source software?

I know all the positives of open source software, but what I am asking is this. Is it possible to make money out of it? If yes, how?

If it isn’t possible, then can we hope for a future where all software will be open source? I doubt there will be many people wanting to "work" for free. Would it attract less people to software development? How will it affect software companies?