Helps if you spin the cog on as tight as you can with a chain-whip. Then use a punch and hammer to really lock down the lockring.
A lot of the problems with cogs coming loose is people don't cinch down the cog tightly first. Even with the lockring tightened on it, chain-torque will still spin the cog away from the lockring and then everything's loose.