how does the earth's magnetic field protect us from cosmic rays
As well as deflecting the solar wind, the Earth's magnetic field deflects cosmic rays, high-energy charged particles that are mostly from outside the Solar system. (Many cosmic rays are kept out of the Solar system by the Sun's magnetosphere, or heliosphere.) By contrast, astronauts on the Moon risk exposure to radiation. Anyone who had been on the Moon's surface during a particularly violent solar eruption in 2005 would have received a lethal dose.