VNC server setup on macOS
This procedure should be attempted only when at the Apple computer physically, as it requires enabling remote access and setting a password for the VNC server, in case something goes wrong and the user is locked out of the computer remotely. For software development on a remote macOS computer, it can be easier to use VSCode over SSH to the remote computer.
As on other operating systems, VNC server on macOS is unencrypted and should be restricted to localhost only, using SSH tunneling for remote access. The VNC server is built into macOS and can be enabled in the System Preferences or via Terminal.
Restrict VNC server to localhost only:
defaults write /Library/Preferences/com.apple.RemoteManagement.plist VNCOnlyLocalConnections -bool yesRestart the VNC server for the change to take effect:
launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plistFrom TigerVNC or other VNC client, the username and password are the same as the macOS user account.
Connect via a new SSH connection:
ssh -L 5900:localhost:5900 user@remotehostStart TigerVNC or other VNC client and connect to localhost:5900 to access the macOS desktop remotely, using the macOS user account credentials.
If the VNC screen is all black, ensure a user is logged in on the macOS computer physically.
If that works, figure out what keystrokes were needed to log in so that when remote, the user can log in without needing to see the screen physically.