Etymology of "son of a gun"
What's the origin of the expression "son of a gun"?
This comic explains a possible origin: British Navy used to allow women on naval ships, and any child born on board who had uncertain paternity would be called "son of a gun" (because "gun" would be a slang for "a military guy"). This is supported by other sources, such as this and this.
But Wiktionary says that "Folk etymologies suggesting nautical origins are not supported by evidence".
Considering those contraditory sources, which one is correct?
Is the kid-born-on-a-ship history true? In case it's not, what would be the origin of this expression?
According to Merriam-Webster, Cambridge and Collins dictionaries, "son of a gun" is an euphemism for "son of a b*tch", but I'm not interested in how the expression became an euphemism, only in its origin, regardless of the meaning it has today.