So you want to put the people underground where they'll be safe, and their source of food and fresh air (the greenhouses) where they're going to be, as you yourself say, vulnerable.
The greenhouses need to be underground as well. So does the power generation, which means a fusion plant. Good thing they're only 20 years away, just like they were 20 years ago.
You can put greenhouses above ground. Just make sure you have an underground failsafe and enough emergency reserves to make it through a disaster.
Even then it's probably not feasible. Look how expensive it is to go underground on earth, now consider how tough it will be on Mars when you're walking around in spacesuits and have to transport heavy duty excavation and construction equipment from earth.
More likely just put everything above ground and distributed. If an asteroid takes out a greenhouse or a house it's tragic, but it doesn't kill the colony.