We determine the anomaly free discrete R symmetries, consistent with the MSSM, that commute with SU ( 5 ) and suppress the μ parameter and nucleon decay. We show that the order M of such Z M R symmetries has to divide 24 and identify 5 viable symmetries. The simplest possibility is a Z 4 R symmetry which commutes with SO ( 10 ) . We present a string-derived model with this Z 4 R symmetry and the exact MSSM spectrum below the GUT scale; in this model Z 4 R originates from the Lorentz symmetry of compactified dimensions. We extend the discussion to include the singlet extensions of the MSSM and find Z 4 R and Z 8 R are the only possible symmetries capable of solving the μ problem in the NMSSM. We also show that a singlet extension of the MSSM based on a Z 24 R symmetry can provide a simultaneous solution to the μ and strong CP problem with the axion coupling in the favoured window.