Vermin are commonly attracted to your compost if it smells of rotting food. Avoid adding grains, meat, eggs and dairy. Check the lid is secure and there are no gaps. Rat-proof your bin by lining the base with chicken wire and sprinkle coffee grounds on top and around your compost bin to mask the smell.
If your compost bin (or worm farm!) is balanced and healthy then it is much less likely to attract vermin, however in some areas there are large populations of rodents endemic, so you need to choose your compost system with this in mind.