Abraham Lincoln was a man Walt Whitman deeply admired and is the captain to whom Whitman refers.
David Reynolds of History Now - American History Online discusses the relationship between the master poet and the fearless leader. He asserts that Whitman looked for a “Redeemer President of These States,” who would come out of the real West, the log hut, the clearing, the woods, the prairie, the hillside.” This "Redeemer President" appeared six years later in the form of Abraham Lincoln. Lincoln did not disappoint his poet admirer and gained stature as Lincoln's presidency progressed and as the North won the Civil War, preserving the Union.
It was Lincoln's death, however, that affected Whitman the most, who memorialized the greatest president in United States History with "O Captain! My Captain!"
(For more information on this poem and Whitman's relationship with Lincoln, check out the History Now website, linked above. For an analysis and a discussion on the meaning of the poem, keep reading.)