While nanoporous graphene oxide (GO) is recognized as one of the most promising reverse osmosis desalination membranes, limited attention has been paid to controlling desalination performance through the large GO pores, primarily due to significant ion leakage resulting in the suboptimal performance of these pores. In this study, we employed a molecular dynamics simulation approach to demonstrate that Mg2+ ions, adhered to carboxylated GO nanopores, can function as gates, regulating the transport of ions (Na+ and Cl-) through the porous GO membrane. Specifically, the presence of divalent cations near a nanopore reduces the concentration of salt ions in the vicinity of the pore and prolongs their permeation time across the pore. This subsequently leads to a notable enhancement in salt rejection rates. Additionally, the ion rejection rate increases with more adsorbed Mg2+ ions. However, the presence of the adsorbed Mg2+ ions compromises water transport. Here, we also elucidate the impact of graphene oxidation degree on desalination. Furthermore, we design an optimal combination of adsorbed Mg2+ ion quantity and oxidation degree to achieve high water flux and salt rejection rates. This work provides valuable insights for developing new nanoporous graphene oxide membranes for controlled water desalination.