"Two Years Before the Mast" is a book by the American author Richard Henry Dana, Jr., published in 1840, having been written after a two-year sea voyage starting in 1834.
While an undergraduate at Harvard College, Dana had an attack of the measles which affected his vision. Thinking it might help his sight, Dana left Harvard to enlist as a common sailor on a voyage around Cape Horn on the brig Pilgrim. He returned to Massachusetts two years later. He kept a diary throughout the voyage.
The term "before the mast" refers to the quarters of the common sailors — in the forecastle, in the front of the ship. Dana did not set out to write "Two Years Before the Mast" as a sea adventure, but to highlight how poorly common sailors were treated on ships.