John A. Shedd. The line is in his 1928 collection of sayings, Salt from My Attic. The computer scientist Grace Hopper used a version of it in the 1980s, which is why it is often credited to her; the credit to Albert Einstein appears only in the 1990s, decades after his death.
What it means
Being safe is not the same as being useful. A ship tied up in harbour is protected, but it was built to go to sea. The line is usually offered as encouragement to take a sensible risk rather than stay where it is comfortable.
Where it comes from
Quote Investigator gives the line on page 20 of Salt from My Attic, published in 1928 by the Mosher Press of Portland, Maine, and confirmed from photographs of the page; The Yale Book of Quotations cites the same book. In 1931 the columnist Ed Howe reprinted several of the book's sayings, this one among them, describing them as sayings “printed privately by an amateur named John A. Shedd”. By 1949 newspapers were using the line as a filler, with Shedd's name attached.
Grace Hopper, the computer scientist and US Navy rear admiral, told the San Diego Union in 1981 that “a motto that has stuck with me is: ‘A ship in port is safe. But that's not what ships were built for.’” She repeated it often and helped make it famous, but she did not coin it. In 1995 a newspaper column credited the line to Albert Einstein, who had died in 1955; Quote Investigator found nothing to support that.