Quick idea: rotate the ship 360 degrees, integrating the magnetic forces. What remains is the magnetic force of the ship itself. In subsequent measurements, subtract this magnetic force to get the component of the magnetic field of the Earth.