Skip to content

Instantly share code, notes, and snippets.

@hfike
Forked from haircut/SetRemoteManagement.sh
Last active March 13, 2019 01:13
Show Gist options
  • Save hfike/9778e0abe4a1bef91d26ec002a00ec6c to your computer and use it in GitHub Desktop.
Save hfike/9778e0abe4a1bef91d26ec002a00ec6c to your computer and use it in GitHub Desktop.
#!/bin/bash
LOCALADMIN="username"
LOCALUSER="username2"
kickstart=/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart
echo "Configuring Remote Management"
if id -u $LOCALADMIN >/dev/null 2>&1; then
echo "Defined local admin account exists"
# Deactivate ARD agent, deny all access
echo "Deactivating ARD agent"
$kickstart -deactivate -configure -access -off
echo "Turning off default AllLocalUsers remote management setting"
defaults write /Library/Preferences/com.apple.RemoteManagement ARD_AllLocalUsers -bool FALSE
# Remove 'naprivs' key from users configured by ARD's -specifiedUSers flag
echo "Removing naprivs key from local users"
RemoteManagementUsers=$(dscl . list /Users naprivs | awk '{print $1}')
for EnabledUser in $RemoteManagementUsers; do
echo "--- naprivs removed from $EnabledUser"
dscl . delete /Users/$EnabledUser naprivs
done
# Turn ARD back on and enable only the specified LOCALADMIN
echo "Reconfiguring ARD for only specified users"
$kickstart -configure -allowAccessFor -specifiedUsers
echo "Setting specified local admin account as ARD user with all privileges"
$kickstart -configure -users $LOCALADMIN -access -on -privs -all
if id -u $LOCALUSER >/dev/null 2>&1; then
echo "Defined local user account exists"
echo "Setting specified local user account as limited ARD user"
$kickstart -configure -users $LOCALUSER -clientopts -setreqperm -reqperm yes
else
echo "--- ERROR: The specified local standard account does not exist."
fi
echo "Set Remote Management Status to show in the Menu Bar"
$kickstart -configure -clientopts -setmenuextra -menuextra yes
echo "Restarting ARD agent"
$kickstart -activate -restart -agent
echo "--- Remote management reset; user ${LOCALADMIN} and user ${LOCALUSER} configured for access"
exit 0
else
echo "--- ERROR: The specified local admin account does not exist."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment