This phrase noted here originates from the 1874 poem 'The Theologian's Tale', and is taken from Henry Wadsworth Longfellow's collection of poems titled, "Tales of a Wayside Inn". In part three, section four, the poem reads, “Ships that pass in the night, and speak each other in passing, / Only a signal shown and a distant voice in the darkness…”

Critics, writers, and others have told us this poem is used as a metaphoric expression. It is being used as a very common saying intended to refer to people who encounter each other only for a short period, share just a few words, and then separate to continue their way. They will never see each other again. On the other hand, it could also simply relate to the individuals that are hardly in the same place at the same time and do not have a significant commonality or connection.

More Info: en.wiktionary.org