I first visited Czechoslovakia in 1989, now divided into the Czech Republic and Slovakia. I noticed that the Czechs greeted each other with "Ahoy!" (spelled "ahoi").  I asked a Czech friend why they used a nautical greeting in a land-locked country such as Czechoslovakia. He said that the history of this greeting was very interesting and shared what he knew with me.

I was told that many years ago, when the British held much control over sea traffic, there were serious problems with pirates and smuggling. The British deployed ships in the coastal waters of Europe to check cargo ships for pirates and pirated wares. When they approached a ship in order to inspect its cargo, the captain or his spokesman would call out, "All heil?" The sailors aboard the ship would answer, "Ship all heil!" Sometimes the inspecting ship became suspicious and there would be a search, but more often, the ship would be allowed to continue on its passage. In dialect, "all heil" sounded more like "ahoy," so that word stuck and soon became a form of greeting among people familiar with the term.

Actually, this form of greeting is much older. In the biblical Easter story, Jesus greeted the women with "all hail!" after his resurrection.

Various forms of the word "Heil" can be found in many old languages. In German, it means health or salvation and during the reign of Adolf Hitler, the German and Austrian people greeted their fuehrer with this term. In England, it came to mean "all's well" (thus the above story) and in other countries, it took on similar connotations. The Czech greeting is simply a modern remnant of what was once a common form of greeting throughout much of Europe.

I also found the following explanation on the Straight Dope website in answer to a questioner:

The term "ahoy" is obviously nautical, although the exact origin is unknown. Some authorities think it dates back to an ancient Viking battle cry. The meaning is the same as "hail!", a salute or greeting.

Eric Partridge traces it to the earlier interjection "hoy!" and the early Dutch "hui!" and perhaps the French "ohé!", all from the Middle Dutch "hoey" or "hode" and possibly derived from Old High German "huota" meaning protection (whence the word "heed"). For what it's worth, a hoy is a small coasting freighter.

"Hoy" does not seem to be related to "hail" which comes from the Old Norse "heill" to the Middle English "hail!" used in greeting.

In English, the first written usage cited by the Oxford English Dictionary is from the 1750s, quoting Tobias Smollet's wonderful Adventures of Peregrine Pickle, a contemporary of Fielding's famous Tom Jones and one of my favorites since high school: "Ho! The house ahoy! What cheer! "

"Ahoy!" was obviously well enough known at the time that Smollet could make a joke of hailing a house rather than a ship.

So the term, although nautical, was used as a hail or call in a broader sense. By the late 1880s, it could also be used as a verb, meaning "to call out 'ahoy!'" The OED cites, " She ahoys the schooner."

Alexander Graham Bell suggested "ahoy!" as the standard telephone greeting, but it didn't catch on--for obvious reasons, you may think. Don't be so sure. Brooklyn College professor Allen Koenigsberg, author of The Patent History of the Phonograph, argues that the word that did catch on, "hello," was previously unknown and may have been invented by the man who proposed it, Thomas Edison. 

Exclamations such as "ho!", "yo!" (can anyone past a certain age see that word without thinking "yo, Adrian"?), "yo-ho!" and even "hi!" derive from "ahoy." (The famous "yo-ho-ho and a bottle of rum" was invented-- or at least made famous--by Robert Louis Stevenson in Treasure Island and was not, in fact, piratical.)

Olivia A. Isil, in When a Loose Cannon Flogs a Dead Horse There's the Devil to Pay (a book of seafaring words used in everyday life), comments that "ahoy!" caught the fancy of the Victorian public, and reminds us that Gilbert and Sullivan operettas are liberally sprinkled with such phrases "to add nautical atmosphere and salt to their characters and skits" --even when a Japanese second trombone sings a song of the sea.

Straight Dope Science Advisory Board