Amtrak serves San Francisco via stations in Oakland and Emeryville (near Oakland), with free shuttle-bus connections to San Francisco's Ferry Building and Caltrain station, and Oakland's Jack London Sq. Amtrak offers rail passes good for 15 days of travel within a 330-day period (from $459).
Most departures from Oakland are short hops to Sacramento, but several daily departures are long-haul trains, with coach service, sleepers and private rooms. The Coast Starlight makes its spectacular 35-hour run from Los Angeles to Seattle via Emeryville/Oakland. The California Zephyr runs from Chicago, through the Rockies and snow-capped Sierra Nevada, to Oakland (51 hours); it's almost always late.