Onychomycosis is a fungal infection of the nails. There are several different fungal bugs that can cause this problem: The most common are the dermatophytes (eg Trichophyton rubrum and T. interdigitale), the yeasts (eg Candida albicans) and less commonly the moulds (eg such as Scopulariopsis brevicaulis and the Fusarium species).
The fungus on its own does not necessarily cause the infection, but the infection will become established in those who are at risk. Those who are immunocompromised are more likely to have an oncychomycosis. The toenails on the feet are especially prone to this as the fungi love a dark and moist environment which is the exact type of environment that you find inside the shoes.