Temporarily disable the GUI (without shutting down the system)
sudo systemctl stop display-manager
This is used to stop the GUI Desktop (GNOME/XFCE) while the server is still running
Permanently disable the GUI (not to start automatically)
To disable the GUI and boot into Command Line (CLI) mode only
sudo systemctl set-default multi-user.target
multi-user.target mode is the mode without GUI
Restart the server for the settings to take effect
Re-enable the GUI
To re-enable the GUI
sudo systemctl set-default graphical.target
Then restart the system
sudo reboot
Summary
Temporarily disable the GUI → sudo systemctl stop display-manager
Permanently disable the GUI (boot to CLI only) → sudo systemctl set-default multi-user.target
Re-enable the GUI → sudo systemctl set-default graphical.target