You already have a sense of the answer, When you put a little magnet near a big one, the little magnet tends to line up with its "north" pole near the "south" pole of the big magnet. I'm assuming of course that the little magnet is free to swing around, like the little magnets in compasses. It turns out the Earth is a big magnet, though it is not a very strong one, so compasses line up in the Earth's field just the way they do near another magnet. It turns out the Earth's "north" magnetic pole is only near, not at, the geographic North Pole. The Earth turns on an axis which passes through the geographic poles. The compass of course points toward the magnetic pole, not the geographic pole. For many purposes, that's close enough, unless you're in the far north.
Extra interesting information: The Earth's magnetic poles move around all the time! They even have swapped places on geological time scales (millions of years). Here is a recent story on CNN (March 20, 2002) on the magnetic north pole's latest wanderings: CNN article on magnetic pole wandering
The magnetic field of the Earth is generated by electrical currents in the molten iron in the core of the Earth. The core is constantly churning around because it is very hot and is exchanging heat with the Earth's mantle (molten rock). This churning can move the magnetic field lines pinned to current loops in the liquid. See this nice site at Scientific American
for more information.
Mike and Tom
(republished on 07/22/06)