While cheesecloth can be used, a tightly woven cloth like muslin or even a coffee filter secured with a rubber band is better for fermenting jars as it provides a better barrier against fruit flies and other contaminants.
When fermenting, you need to allow gases produced by the fermentation process to escape while preventing unwanted microorganisms and pests from entering. Cheesecloth, with its loose weave, can sometimes allow small fruit flies or mold spores to pass through. A tightly woven cloth, such as muslin, tightly woven cotton, or even a double layer of coffee filter paper, offers a much finer barrier. These materials still allow for gas exchange but significantly reduce the risk of contamination. Secure the cloth tightly with a rubber band or jar ring to ensure a good seal. The goal is to create an environment that favors the growth of your desired cultures while keeping out anything that could spoil your ferment.
Inspect your fermenting jar daily for any signs of mold or fruit flies, even if you're using a tightly woven cloth. Early detection is key to preventing a ruined batch. If you see any issues, discard the batch immediately to avoid potential health risks.