Skip to content

Instantly share code, notes, and snippets.

@pmbuko
Last active February 15, 2022 00:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pmbuko/5415282 to your computer and use it in GitHub Desktop.
Save pmbuko/5415282 to your computer and use it in GitHub Desktop.
This script will add local admin accounts to ssh_access group in Mac OS X. (10.7 or higher. May also work in 10.6)
#!/bin/bash
# set the input for lazy convenience
IFS=$' '
localadmins=$(/usr/bin/dscl localhost -read /Local/Default/Groups/admin GroupMembership | awk -F': ' '{print $2}')
for account in `echo $localadmins`; do
# add additional blocks like >> && ! [ "$account" == "username" ] << for additional exclusions
if ! [ "$account" == "root" ] && ! [ "$account" == "itstech" ]; then
userID=$(/usr/bin/dscl localhost -read /Local/Default/Users/$account | grep GeneratedUID | awk '{print $2}')
if [ "$userID" != "" ]; then
# We first need to test if the access_ssh group exists and create it if it doesn't
/usr/bin/dscl localhost -read /Local/Default/Groups/com.apple.access_ssh > /dev/null 2>&1
rc=$?
if [[ $rc != 0 ]]; then
/usr/bin/dscl localhost -create /Local/Default/Groups/com.apple.access_ssh
/usr/bin/dscl localhost -append /Local/Default/Groups/com.apple.access_ssh RealName 'Remote Login Group'
/usr/bin/dscl localhost -append /Local/Default/Groups/com.apple.access_ssh PrimaryGroupID 123
fi
/usr/bin/dscl localhost -append /Local/Default/Groups/com.apple.access_ssh GroupMembership "$admin"
/usr/bin/dscl localhost -append /Local/Default/Groups/com.apple.access_ssh GroupMembers "$userID"
else
echo "$account has no local GUID"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment