How can electric charges be produced by rubbing?
Electric charge is the result of excess or insufficiency of electrons (negatively charged particles) as compared to protons (positively charged particles). It can be achieved by the process of rubbing two materials against each other, during which the electrons migrate from one material to another.
The result of rubbing is capturing of certain number of electrons by one material from another. As a consequence of this migration of electrons, the material that captures them becomes negatively charged (because of excess of electrons over protons), while another material simultaneously becomes positively charged (because of insufficient number of electrons relatively to protons).
The migration of electrons depends very much on the properties of materials rubbed against each other and happens only if one of the materials is a stronger holder of its electrons than another.
It should be added that, unlike heavy protons, that are carriers of positive electric charge, light negatively charged electrons are always moving inside the material forming an "electron cloud" and, therefore, can migrate from from one material to another during rubbing, if forces that hold electrons inside one of the materials are significantly stronger than corresponding forces of the other.