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{double-struck}MR symmetries has to divide 24 and identify 5 viable symmetries. The simplest possibility is a Z{double-struck}4R symmetry which commutes with SO(10). We present a string-derived model with this Z{double-struck}4R symmetry and the exact MSSM spectrum below the GUT scale; in this model Z{double-struck}4R originates from the Lorentz symmetry of compactified dimensions. We extend the discussion to include the singlet extensions of the MSSM and find Z{double-struck}4R and Z{double-struck}8Rare 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{double-struck}24Rsymmetry can provide a simultaneous solution to the μ and strong CP problem with the axion coupling in the favoured window. © 2011 Elsevier B.V.