Some fans have theorised that it was derived from "smegma" (a particularly unpleasant bodily secretion), but Rob and Doug deny this

The lady[-ies] doth protest too much!

This is absolute rot (the denial, that is). Kids - especially boys, bless 'em - have been talking about smeg for ages, long before Red Dwarf. And it came straight out of Biology lessons, Sex Education, and the odd Dictionary trawl, like so many other pubescent gems.

The Red Dwarf people have, however, had considerable success in sanitizing the term. Not the first time a very crude phrase has come into fairly wide acceptance through ignorance of its root meaning.

Oh, and shanks - confusing Scouse and Brummy - for shame!
(mind you, I'm married to a Brummy, so should know the difference. cf Frank Skinner for a mild Brummy accent, incidentally)

All you people over the Pond - yep, see Red Dwarf. Though IMHO you're best off with the 3rd series onwards.