I know that today, if I take a cruise of the Mediterranean, then each time the boat stops in a new country, and I wish to go ashore and see the sites, that I will need to have appropriate documentation. At some location near the docks, I will be greeted by a uniformed agent of the host nation, who will inspect my passport, ensure the proper visas exist if required, and possibly search any day-pack I am carrying. I am interested in learning the history of this concept, at least from the last few hundred years.
As an example, let us suppose that I am a sailor from S, crewing on a barquentine carrying metals prevalent in S’s mines, but absent in N. Meanwhile, we in S really like the textiles they produce in N, and willingly trade. We sail back and forth a couple times a year- taking metal one direction and bringing textiles back the other direction. Sometimes, when we moor at the docks in N, I and my mates might wish for a period of shore leave. We want to stay in the inn, pour down the ales, and flirt with the barmaids.
As such a sailor, when would I have first encountered any sort of check by the hosts? When would I first have needed identification or a document like a passport? When were the first ministries/ departments of customs and immigration created, and where?
Similarly, what about those tradesmen who accompanied the crusades, crossing several borders along the way? Or perhaps minor nobles going to visit one another? When did border checks begin, and how did they evolve into the formal event we have today?
I have attempted a little research, but so far all I can find are articles discussing major immigrations, i.e. of religiously oppressed peoples, not the casual traveler or visitor.