It is claimed that in British naval slang this term refers to a child of questionable parentage conceived on the gun deck, hence 'son of a gun'. However, the term possibly predates this claimed origin, and Snopes.com lists it as being part of the English lexicon since at least 1708.1 It is sometimes claimed that the saying has its origin in the supposed practice of women travelling on board ship and giving birth on a sectioned off portion of the gun deck. For instance, Admiral William Henry Smyth wrote in his 1867 book, The Sailor's Word-Book:2 Son of a gun, an epithet conveying contempt in a slight degree, and originally applied to boys born afloat, when women were permitted to accompany their husbands to sea; one admiral declared he literally was thus cradled, under the breast of a gun-carriage.
edit American English
In American folk idiom (American), this term has similar meaning to the British one, but was derived from military bureaucratic treatment of young enlisted men of uncertain familial background. If a recruit was unable to state his father's name, officers recorded "A. Gun".citation needed
son of agun stfu nigger gun!
THIS SON OF AGUN FUCKS HIS GUN ; HZE MUST HAVE A THIN COCK