Sure-fire: where does it come from?
According to the Oxford dictionary:
Sure-fire: (adjective, informal) certain to succeed. Example: bad behaviour is a sure-fire way of getting attention
Where does this word combination come from and does it have anything to do with fire?
Etymonline says:
surefire (adj.) also sure-fire, by 1864, American English, from sure + fire (v.). Originally of rifles.
Since early rifles were rather less than completely reliable, a "sure-fire" rifle would be highly regarded.
In the literal sense it dates at least as far back as 1837, as shown in an advert for gunpowder in the Vermont Watchman and State Journal (Montpelier, Vt.) of November 27, 1837:
The Burlington Free Press (Burlington, Vt.), July 08, 1842 refers to sure fire guns:
As does Sunbury American (Sunbury, Pa.), September 13, 1856:
As a supplement to Hugo's excellent answer, I note several somewhat earlier instances of "sure fire" in the sense of successful and accurate firing of cannons or guns. First, from a letter from J.J.U. Rivardi to the U.S. Secretary of War dated April 13, 1794, reprinted in Documents, Legislative and Executive, of the Congress of the United States (1832):
The lower battery's greatest defect, in point of construction, ism that a vessel, after having passed the upper reef, can with ease pour its broadside in the side of the guns; this enfilade is prevented by raising the epaulement, 1, 2, 3, which affords, likewise, sufficient room to pursue, with a sure fire, a vessel which should have succeeded in passing; whereas the battery, in its present situation, must be abandoned, as soon as a vessel, even of a few guns, passes the point.
From "Is Death at Distance?" in The Guardian, or Youth's Religious Instructor (May 1821):
Didst thou ever see the beautiful bird, unconscious of danger, spreading her wings to the sun? Didst thou mark the fowler's sure fire? See, from her summit of glory pierced to the heart—fluttering she falls lifeless to the ground. Learn then thy danger—thou art the bird—Death is the fowler, and ere thou art aware, thou mayest become his victim.
From references to certain "properties" to be included in a production of John Banim, The Sergent's Wife: A Drama in Two Acts ("First performed at the English Opera House, on Tuesday, July 24, 1827):
[Act 2, Scene 2.—] Old sofa on L. C. close to flat ; blue bottles 2 E. R. H. to reflect on Lisette at "then I'm safe yet" ; pistol for Margot, light torch for prompter behind flat at "See, as the girl told me!" two pistols, sure fire 4 E. L. at "but one stroke!"
Scene 3.—Old panel chamber 1 G. Two pistols sure fire L. H. 3 E. at "Sound asleep I warrant."
From Commonwealth v. Jones (November 1829), reprinted in Reports of Cases Argued and Determined in the Cases Court of Appeals, and in the General Court, of Virginia, volume 1 (1830):
He dressed his would, adjusted his clothes, and, being apparently composed, deliberately armed himself with a dirk, or, being already thus armed, went abroad a considerable distance in quest of a gun ; chose one with cautious circumspection and judgment ; deliberately tried its fitness for the object he had in view, a sure fire; primed, snapped, and flashed it; procured powder and lead, and loaded it; and, thus armed with a drawn dirk, and a loaded gun, traversed the public streets, passed the market place, where, perchance, he might meet the deceased, and, finally, sought him at his boat where he found him ; and then, with deliberate aim, shot him to death, while the deceased was unarmed, unresisting, and in actual flight from him..
From "Tar and Feathers Revenged," in the [Lawrenceburgh] Indiana Palladium (November 28, 1835), reprinted from the New York Transcript:
Ditson was again present at the battle of Bunker Hill; where he had an opportunity of using the old musket to still greater advantage than at the battle of Lexington. Reserving his fire agreeably to the mode enjoined by Putnam until he could see the enemies' eyes, he brought down his man at every shot; and several more, whose countenances he recollected, as having belonged to those engaged in the tarring and feathering scrape fell victims to the strength of his memory, the accuracy of his aim, & the sure fire of his rusty old piece.
From Charles Ball, Slavery in the United States: A Narrative of the Life of Charles Ball, a Black Man (1836):
He also gave me an old gun, that had seen much hard service ; for the stock was quite shattered to pieces, and the lock would not strike fire. I took my gun to a blacksmith, in the neighbourhood, and he repaired the lock, so that my musket was as sure fire as any piece need be. I found upon trial, that though the stock and lock had been worn out, the barrel was none the worse of the service it had undergone.
The earliest two instances—from 1794 and 1821—seem to be using "sure fire" to mean "accurate shot," first in the case of a battery of cannons and second in the case of a fowling piece. The third, fourth, fifth, and sixth instances, however, seem to emphasize "sure fire" in the sense of "certain to ignite the gunpowder and (therefore) fire a loaded bullet." The last of the six examples, from 1836, is explicit that the author's musket had had a faulty flintlock that "would not strike fire" but that the blacksmith had corrected this fault so that the gun was once again "sure fire."
Instead of a fire that you light, think of a rifle that you fire.
Etymology online says
also sure-fire, by 1864, American English, from sure + fire (v.). Originally of rifles.
Dictionary.com puts the date around 1915-1920.