Skip to content

Instantly share code, notes, and snippets.

Created May 28, 2022 13:02
What would you like to do?
macOS enable vnc remotely via ssh
# simple script to enable remote management via an ssh
set -e
if [ "$EUID" -ne 0 ]
then echo "please run as root (eg: sudo $0)"
# bins
echo "[+] configuring remote management via vnc"
$KICKSTART -configure -allowAccessFor -allUsers -privs -all
$KICKSTART -configure -clientopts -setvnclegacy -vnclegacy yes
$KICKSTART -configure -clientopts -setvncpw -vncpw $VNCPASS
$KICKSTART -activate
$KICKSTART -restart -agent -console
echo "[+] enabling remote management via vnc"
defaults write /var/db/launchd.db/ -dict Disabled -bool false
# only allow VNC connections from localhost. aka: use an SSH tunnel to forward 5900
defaults write /Library/Preferences/ VNCOnlyLocalConnections -bool yes
echo "[+] restarting screensharing service"
launchctl unload /System/Library/LaunchDaemons/
launchctl load -w /System/Library/LaunchDaemons/
echo "[+] done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment