Using the quantum-mechanical approach combined with the image charge method we calculated the lowest energy levels of the impurities and neutral vacancies with two electrons or holes located in the vicinity of flat surface of different solids. Unexpectedly we obtained that the magnetic triplet state is the ground state of the impurities and neutral vacancies in the vicinity of surface, while the nonmagnetic singlet is the ground state in the bulk, for e.g. He atom, Li+, Be++ ions, etc. The energy difference between the lowest triplet and singlet states strongly depends on the electron (hole) effective mass μ, dielectric permittivity of the solid ε2 and the distance from the surface z0. For z0=0 and defect charge ∣Z∣=2 the energy difference is more than several hundreds of Kelvins at μ=(0.5-1)me and ε2=2-10, more than several tens of Kelvins at μ=(0.1-0.2)me and ε2=5-10, and not more than several Kelvins at μ<0.1me and ε2>15 (me is the mass of a free electron). Pair interaction of the identical surface defects (two doubly charged impurities or vacancies with two electrons or holes) reveals the ferromagnetic spin state with the maximal exchange energy at the definite distance between the defects (∼5-25 nm). We estimated the critical concentration of surface defects and transition temperature of ferromagnetic long-range order appearance in the framework of percolation and mean field theories, and RKKY approach for semiconductors like ZnO. We obtained that the nonmagnetic singlet state is the lowest one for a molecule with two electrons formed by a pair of identical surface impurities (like surface hydrogen), while its next state with deep enough negative energy minimum is the magnetic triplet. The metastable magnetic triplet state appeared for such molecule at the surface indicates the possibility of metastable ortho-states of the hydrogen-like molecules, while they are absent in the bulk of material. The two series of spectral lines are expected due to the coexistence of ortho- and para-states of the molecules at the surface. We hope that obtained results could provide an alternative mechanism of the room temperature ferromagnetism observed in TiO2, HfO2, and In2O3 thin films with contribution of the oxygen vacancies. We expect that both anion and cation vacancies near the flat surface act as magnetic defects because of their triplet ground state and Hund's rule. The theoretical forecasts are waiting for experimental justification allowing for the number of the defects in the vicinity of surface is much larger than in the bulk of as-grown samples.