How do boats with holes in their hulls for the propellar keep out water?

The propeller is at the end of a shaft. The shaft passes through a fitting called a stuffing box. The stuffing box contains a material like cotton or waxed twine that wraps around the shaft. There are two or more bolts that hold the stuffing box together and by tightening or loosening the bolts you can squeeze or release the stuffing material to the shaft. Ideally you tighten the bolts to the point that water just drips in.

This allows the shaft to spin freely. It is lubricated by the water. If you tighten the box too much then you can score the shaft.
The water that drips in is usually pumped out by a bilge pump.