As snug as a bug
This phrase first appeared in print in 1769 - more on that later. In order to trace its etymology we'll need to check out what was meant by 'snug' and 'bug' in the 18th century.
'Snug' was first used to mean 'neat; trim; well prepared' and referred specifically to ships. It is used that way in Captain Wyatt's recounting of The Voyage of Robert Dudley, circa 1595:
A verie fine snugg long shipp
In 1630, John Lane wrote The Continuation of Chaucer's Squire's Tale and referred to another meaning for 'snug' - or possibly simply a modified form of the earlier meaning - the one we use today, that is, 'comfortable and cosy'.
Snugginge they in cabins lay each one.
Etymology meets etymology in tracing the origin of 'bug' - not an especially productive meeting as it turns out, as no one is entirely sure why insects are called bugs. Before they were insects, 'bugs' were ghosts or ghouls. The Coverdale Bible, 1535, referred to 'bugges' in that way, in Psalms 91:5:
So yt thou shalt not nede to be afrayed for eny bugges by night, ner for arowe that flyeth by daye.
How 'bug' became used to mean beetle or grub isn't clear, but we do know the meaning was in use by 1642, when Daniel Rogers published Naaman the Syrian:
Gods rare workmanship in the Ant, the poorest bugge that creeps.
You might think that the extended version 'as snug as a bug in a rug' came about in a 'been there done that, got the tee shirt' kind of way. In fact, the longer version is the original. The first known example of the phrase in print is found in the account of David Garrick's celebration of Shakespeare Garrick's vagary, or, England run mad; with particulars of the Stratford Jubilee, 1769:
If she [a rich widow] has the mopus's [coins or money], I'll have her, as snug as a bug in a rug.
As 'rug' has entered the equation, it's worth looking at the origin of that too. 'Rug' is a Tudor word with the same source as 'rag', but Henry VIII wouldn't have walked on his rugs as they were originally thick woollen bed coverlets - pretty much what we would now call blankets. It wasn't until the early 19th century that rugs were put on the floor. The first of their kind were hearth-rugs, as referred to in Londinium redivivum; or An antient history and modern description of London, 1803:
The antient hall is rented... for a carpet and hearth-rug warehouse.
The link between rag and rug is a close one - rugs were made from rags. Not so long ago, certainly within my memory, hearth-rugs were made by pulling strips of rag through sacking. These rag rugs, or peg rugs as they were also called, are still not difficult to find in the UK.
The format 'as X as Y' runs though the English language and there are many examples. The 'X' in question invariably refers to a property that 'Y' typically possesses. It's hard to imagine a place more congenial for a bug to snuggle down than a warm hearth-rug. The first such 'bug in a rug' was probably a cricket; these creatures are attracted to warmth and congregate in buildings around ovens and open fires.
See other 'as X as Y ' phrases.