Old English sceaft "long, slender rod of a staff or spear," from Proto-Germanic *skaftaz (cf. Old Norse skapt, Old Saxon skaft, Old High German scaft, German schaft, Dutch schacht, not found in Gothic), which some connect with a Germanic passive past participle of PIE root *(s)kep- "to cut, to scrape" (cf. Old English scafan "to shave") on notion of "tree branch stripped of its bark." But cf. Latin scapus "shaft, stem, shank," which appears to be a cognate. Meaning "beam or ray" (of light, etc.) is attested from c.1300. Vulgar slang meaning "penis" first recorded 1719.
"long, narrow passage sunk into the earth," early 15c., probably from shaft (n.1) on notion of "long and cylindrical," perhaps as a translation of cognate Low German schacht in this sense (Grimm's suggestion, though OED is against it). Or it may represent a separate (unrecorded) development in Old English directly from Proto-Germanic *skaftaz in the original sense of "scrape, dig." The double sense of shaft is attested in country music song title, "She Got the Gold Mine, I Got the Shaft."