If you rub your eyes with dirty hands, the bacteria on your hand may get into your eyes and further cause an eye infection. There are many bacteria around us. We can't see bacteria with our eyes because they are too small. Some of them will not cause big problems. But there are few ways to protect ourselves. The easiest way is to wash our hands with soaps for several times per day and avoid touching dirty stuffs.
Pets can be a cause of bacterial eye infections. Pets don't have clothes and don't take shower every day and their feet are always on the ground. So I think they carry lot of bacteria with them. If you have a pet, you must take it to have a shower at least every two days.