Naval architect here, second question of the week I can answer!
At least for European sailors the simple answer is that they didn't. Sailing ships of that era went to sea with massive barrels in their hull to hold drinkable fluids. Ships that took to the open ocean on long voyages typically had a cooper onboard to maintain them, and one of the daily tasks of the ships steward (if there was one) was to sound the casks and keep track of how much remained. It's one of the things you find noted a lot in log books from the Royal Navy and various whaling ships.
Putting in to shore to take on water was not an uncommon emergency, especially in the tropics. Furthermore, dying of dehydration became a serious concern when ships were becalmed.
Note fluids not water since it would mostly have been weak beer. For a variety of reasons water tended to go bad on long voyages (If it was ever drinkable to begin with).
There was no practical way to get fresh water at sea.
Edit: a sailor went to sea sea sea to see what he could see see see, damn auto correct.
Edit 2: for the curious, the mystic seaport museum sells copies of ships logs from whaling for research purposes. They are actually an important resource for climate, anthropology, biology, etc since the rule was to write detailed records of location, weather, and goings on.
Edit3: lots of people from military (and coast guard) backgrounds commenting about their experiences with osmosis and desalination plants on all manner of military vessels. My experience is mostly with the design of civilian vessels which admittedly have very different design priorities from naval vessels.
Edit4: I may have hallucinated this but someone asked about drunken sailors. The original comment is not here but I can only assume the question was "what did they do with a drunken sailor?". As noted, the beer provisioned on ships had much lower alcohol content so people weren't usually getting drunk off it. This was not the only alcohol onboard though and there is ample evidence of sailors having one too many.
Historical evidence suggests punishments for drunkenness ranging from shaving the drunkards midriff with a dull razor to allowing the offender to sleep it off in the ship's boat.
https://en.wikipedia.org/wiki/Drunken_Sailor?wprov=sfsi1
Seriously though, drunkenness aboard ship was much rarer than you might believe given the cliche. Sailing ships were incredibly dangerous and being drunk was not taken lightly. Punishment was at the discretion of the captain, but usually involved some variation of flogging. http://www.cnrs-scrn.org/northern_mariner/vol09/nm_9_1_53to66.pdf
Gordon Miller, in his delightful book Voyages: To the New World and Beyond (2011, University of Washington Press) states that during his exploration of the southern seas in 1773, Captain James Cook discovered that sea ice (icebergs) contained fresh water, and "...when seas were calm, his ships filled their casks from the unlimited supply of fresh water."