I'm running macOS Mojave on a Mac Mini. Built-in VNC server works perfectly when you connect for the first time after reboot, however if you disconnect from it for more than five minutes you can't connect again – it displays the username that was used for the last session and a spinning wheel. Connecting via ssh and killing screensharingagentd doesn't help, only a reboot does. I've verified all the power saving settings are off. There are two virtual machines with macOS High Sierra and Sierra running on this same Mac Mini and I can connect to them without any issues.
Screen sharing stops working after disconnecting for about five minutes
remote desktop
Best Answer
My workaround for this problem is to login via ssh and kill loginwindow process:
This will allow to login via VNC then.