Keep your hands clean / keep your nose clean
Be innocent of any wrongdoing; stay out of trouble.
'Keeping one's hands clean' is an 18th century English phrase which referred specifically to the avoidance of corruption. Moral authorities of the time would have shuddered to use the word masturbation, but that is probably what they were getting at. The earliest citation that I have found of the term in print is from a collection of sermons, published in London in 1711, under the title of The Golden Remains of the ever memorable Mr. John Hales:
"Suppose ye unto your selves some such Man as Epictetus was, let him have all Graces that are, piety only excepted, let him wear out himself with Studies, pine himself with Temperance, keep his Hands clean from Corruption, his Heart from unchaste Desires."
Mr. Hales clearly set the bar rather high in terms of moral virtue.
'Keeping one's hands clean' took some time to become widely used but it is commonly found in later 18th century literature.
For some reason, when the phrase crossed the Atlantic, it was the nose rather than the hands that people were urged to keep clean. Now that the phrase has taken the return journey across the seas and back to the UK, the context there is usually directly related to the world of crime. It has become something of a cliché of crime dramas that, on being released from jail, lags are warned by officials to "keep your nose clean and don't let me see you back here".
Both the 'nose' and earlier 'hands' variants of this phrase mean much the same thing. The American 'keep your nose clean' may be an allusion to keeping one's nose out of the trough or corruption. Many of the early citations of it appear in lists of virtuous actions encouraged by moral authorities and may simply allude to not putting one's nose into other people's business, or even simply not letting one's nose run with mucous. The later (early 20th century) usage in the British Army appears to relate specifically to avoiding strong drink. Presumably the allusion there is to avoiding putting one's nose in the glass. The earliest example that I've found of the phrase in print is from the Kansas newspaper The Globe, May 1881:
"Mr. Lowell commenced railroading about sixteen years ago, as superintendent's private secretary, and by keeping his nose clean, brushing his clothes, and attending Sunday school regularly, he has succeeded so well..."