Last active
February 15, 2022 00:53
-
-
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)
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 | |
# 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