Wikipedia has a good entry on the tradition of the ship’s cat. While their services were mainly needed for rodent control, they provided comfort to the crew as well:
Cats have a high ability to adapt to new surroundings, and were therefore highly suitable for service on a ship. They also offered companionship and a sense of home and security to sailors who could be away from home for long periods, especially in times of war.
The page includes several photos, including this one (caption by Wikipedia):