Stellar magnetic fields have a major impact on space weather around exoplanets orbiting low-mass stars. From an analysis of Zeeman-broadened Fe i lines measured in near-infrared SDSS/APOGEE spectra, mean magnetic fields are determined for a sample of 29 M dwarf stars that host closely orbiting small exoplanets. The calculations employed the radiative transfer code Synmast and MARCS stellar model atmospheres. The sample M dwarfs are found to have measurable mean magnetic fields ranging between ∼0.2 and ∼1.5 kG, falling in the unsaturated regime on the 〈B〉 versus P
rot plane. The sample systems contain 43 exoplanets, which include 23 from Kepler, nine from K2, and nine from Transiting Exoplanet Survey Satellite. We evaluated their equilibrium temperatures, insolation, and stellar habitable zones and found that only Kepler-186f and TOI-700d are inside the habitable zones of their stars. Using the derived values of 〈B〉 for the stars Kepler-186 and TOI-700 we evaluated the minimum planetary magnetic field that would be necessary to shield the exoplanets Kepler-186f and TOI-700d from their host star’s winds, considering reference magnetospheres with sizes equal to those of the present-day and young Earth, respectively. Assuming a ratio of 5% between large- to small-scale B-fields, and a young-Earth magnetosphere, Kepler-186f and TOI-700d would need minimum planetary magnetic fields of, respectively, 0.05 and 0.24 G. These values are considerably smaller than Earth’s magnetic field of 0.25 G ≲ B ≲ 0.65 G, which suggests that these two exoplanets might have magnetic fields sufficiently strong to protect their atmospheres and surfaces from stellar magnetic fields.