macOS enable vnc remotely via ssh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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