I have a Raspberry Pi running well in headless mode. I am comfortable running things from the command line, and so have it set to boot to CLI. I use PuTTY from Windows 10 to run any commands etc.

Occasionally, however, I would like to do something from the Desktop GUI (using the mouse for a lot of drag & drop kind of tasks), and I have VNC to operate this. My problem is that I don't know how to turn off the Desktop GUI again once I'm done. Currently I have two methods available to me - one that works (but isn't ideal) is I can get on the Pi itself and run


This starts the GUI, then I can connect using VNC and do whatever I need to do, and have the option from the GUI to "Exit to command line", which closes the Desktop and puts the Pi back into CLI only.

enter image description here

However I have to get on the Pi itself to do this, I can't start that remotely (since PuTTY isn't graphical).

So from PuTTY I have been starting the desktop service

sudo systemctl start lightdm

Which allows me to then connect to the Desktop using VNC as desired, but I no longer have the option "Exit to command line" from the Shutdown menu

enter image description here

I can open the PuTTY terminal and stop the service, but this does not put the Pi back into CLI - if I get on the Pi directly I'm met with a blank screen and blinking cursor and am unable to do anything from there (although a PuTTY terminal still works).

enter image description here

How can I remotely start the Desktop GUI for use with VNC, and be able to close that GUI again once I'm done?

Trying to do this with both RPi 4B and 3B+, so looking for answers that could work in both, but mostly need it for the 4.

1 Answer 1


You appear to want to start a Desktop - which you can only do on the Pi itself.

If you want a desktop you can start/stop remotely you can create a Virtual Desktop

NOTE this Virtual Desktop will NOT share the screen with a real display.

There is no reason to exit GUI to get a command window.

If you just want to get to a CLI Ctl+Alt+F2 will get you a session you can login to. Ctl+Alt+F7 would switch back to the GUI

PS you can use any of F1-F6. F1 is the boot login

  • A Virtual Desktop appears to be exactly what I'm after, thank you! I can start the Desktop, do whatever I'm needing to do, and I'm even presented with the "Exit to command line" which terminates the Virtual Desktop when I'm done.
    – Midavalo
    Dec 27, 2019 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.