The Magnetic Field is created somehow in the core by unknown origins (speculation suggests that it’s created from the spinning liquid outer core)
It blocks most of the solar wind and some solar wind goes through the poles and creates aurora borealis.
Magnetic fields can be produced by moving electric charges and the intrinsicmagnetic moments of elementary particles associated with a fundamental quantum property, their spin.