Don't do their loyalty mission or assign them for tasks during the suicide mission they aren't suitable for. In certain cases it could still be possible they live through it - Miranda for example won't die since she still makes a default return in ME3.

Not true. You can get everyone killed in the SM, which results in Shepard dying at the end. In terms of the "ship deaths", you can skip those upgrades and then simply take the two people you want to live through that part with you to fight the Collector Drone that boards the ship. Also keep in mind that sending people that are ill suited for the various tasks generally doesn't get THEM killed, but rather someone else on the team. For example, if you send Miranda into the vents, she won't die. Someone from the second fire team will because she's not the right person to open the door quickly.

@ Bearwithbeard: Also not true. I never bring Mordin along with me, and he never dies. I generally use him for my escort service, but I've left him to hold the door too and he made it. The only way anyone dies from the seeker swarms is if you chose poorly for you barrier person. That would be either Miranda, or a disloyal Samara/Jack.