The ability to make material charged by rubbing is called the "triboelectric effect" – "tribo-" is related to rubbing in Greek. When two materials are in touch, a chemical bond develops between the surface molecules of both material, because of differences in their electrochemical potential. When separated, the electrons may stay with one of the materials.
Just for the sake of the argument, imagine that you "rub" Na and Cl. They naturally produce molecules of NaCl on the interface. But the molecule is really Na+Cl−Na+Cl−, so when you separate them, the Na molecule remains positively charged while the chlorine is negatively charged. This is not a realistic example because Cl is a gas :-) but it works in a similar way for more realistic materials.