Your best bet is not to live in cities themselves. Live in a town just outside of them that's within a reasonable commuting distance.

But yeah, high rent is exactly why places like San Francisco are having so many problems with homeless people everywhere. Many of them even have full-time jobs, but rent's just too high for them to live anywhere in town.