I found a solution which works for me.
sudo pkill -9 -u 0 -fx '/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow' instead of
sudo pkill loginwindow
I originally used the answer from MacOS Mojave remote access login screen stuck on infinite loading spinner but logging out everything became a problem. I ran
pgrep loginwindow and found I was killing two processes.
ps -f on those two PIDs gave me:
UID PID PPID C STIME TTY TIME CMD
XXX XXX 1 0 11:28PM ?? 0:06.58 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow console
0 XXX XXX 0 5:47PM ?? 0:00.21 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow
Killing the nonconsole process allowed the VNC connection to succeed with no spinning wheel.
My new process is:
- Close VNC/Screen Sharing Window
- Connect via ssh:
sudo pkill -9 -u 0 -fx '/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow'
- Connect using VNC as usual