Earth's planetary defenses had several access codes which were known to Starfleet captains. Nero captured Christopher Pike and tortured him to learn the codes. The defenses were inoperable when Nero started drilling into San Francisco bay, though the timely arrival of the USS Enterprise stopped him. (Star Trek)