The trick here is not only to avoid all obvious sources of carbohydrate (sweets, bread, spaghetti, rice, potatoes), but also to be careful with your protein intake. If you eat large amounts of meat, eggs and the like, the excess protein will be converted into glucose in your body. Large amounts of protein can also raise your insulin levels somewhat. This compromises optimal ketosis.
In a way, moderate-intensity physical activity is that "magic pill" a lot of people are looking for, because the health benefits go beyond keeping your waistline trim: Not only can it reduce your risk of cancer, stroke, diabetes and heart attacks, but studies have shown that physical activity can significantly improve the moods of patients with major depressive disorders.