Skip to content

Instantly share code, notes, and snippets.

@leonjza
Created May 28, 2022 13:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leonjza/c3b68432b0c2e486587a7c53c4d366bc to your computer and use it in GitHub Desktop.
Save leonjza/c3b68432b0c2e486587a7c53c4d366bc to your computer and use it in GitHub Desktop.
macOS enable vnc remotely via ssh
#!/bin/bash
# simple script to enable remote management via an ssh
set -e
if [ "$EUID" -ne 0 ]
then echo "please run as root (eg: sudo $0)"
exit
fi
VNCPASS=SomePasswordHereMakeItAGoodOneOfc
# bins
KICKSTART=/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart
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/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false
# only allow VNC connections from localhost. aka: use an SSH tunnel to forward 5900
defaults write /Library/Preferences/com.apple.RemoteManagement.plist VNCOnlyLocalConnections -bool yes
echo "[+] restarting screensharing service"
launchctl unload /System/Library/LaunchDaemons/com.apple.screensharing.plist
launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
echo "[+] done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment