The natural magnetic field within and surrounding the Earth is termed terrestrial magnetism.
Terrestrial magnetism is formed due to the circulating ions that are highly conducting in the core of the earth which results in the formation of the current loops and these current loops produce the magnetic field.
When a magnetic body is buried inside the earth in a north-south direction, it starts feeling magnetic effects and gets magnetized due to the effect of terrestrial magnetism.