It's a well known pirate song.
From
Rogues Cove Maritime Society Inc.:
Note: This song was written in 1901 for a Musical based on the book Treasure Island. It is based on a few verses presented in the book. As R.L. Stevenson did a considerable amount of research on pirates, it is possible that some of the verses that appeared in his book are genuine and period..