Hi,
the line
if id tempadmin &>/dev/null;
is going to return false and will never enter the then part of the removal script.
you can check this by simplydoing a short test on your system with:
if [ id NameofExistingUser &>/dev/null ]; then
echo "true"
else
echo "false"
fi
which just reminds one of the fact that one should always check there if statement outputs when possible
If the admin account you are creating inherits a Secure Token, you cannot use Jamf to delete it. To delete a Secure Token holding account, you need an account with a Secure Token. Jamf runs everything as root, which does not have a Secure token and in turn cannot modify a Secure Token holding account.
Though, I would question the security of creating a local admin account from CLI as the username and password can be intercepted simply enough by a malicious actor.
Thanks both.
@AJPinto - The command "sysadminctl -secureTokenStatus tempadmin" returns "Secure token is DISABLED for user tempadmin".
@Ismere - I updated the IF statement in the removal script but it didn't seem to have any effect. Instead, for troubleshooting, I removed the IF statement.
The removal script is now:
# Create a removal script using tee in a HERE document
tee /Library/Scripts/removeTempAdmin.sh << EOS
# Delete the temp admin user
#sudo sysadminctl -deleteUser tempadmin
#sudo dscl . -delete /Users/tempadmin
sudo jamf deleteAccount -username tempadmin -deleteHomeDirectory
# Provide feedback to user
sudo osascript -e "display dialog \\"You administrative rights have ended.\\" with title \\"Temporary Admin Account\\" buttons {\\"OK\\"} default button \\"OK\\""
# Bootout the launch daemon
sudo launchctl bootout system /Library/LaunchDaemons/removeTempAdmin.plist
# Delete the daemon
sudo rm /Library/LaunchDaemons/removeTempAdmin.plist
EOSThe three account deletion commands fail in the script yet all work manually via CLI. Bootout now works but the daemon isn't deleted. If delete the daemon first that will work but then bootout fails.
Thanks both.
@AJPinto - The command "sysadminctl -secureTokenStatus tempadmin" returns "Secure token is DISABLED for user tempadmin".
@Ismere - I updated the IF statement in the removal script but it didn't seem to have any effect. Instead, for troubleshooting, I removed the IF statement.
The removal script is now:
# Create a removal script using tee in a HERE document
tee /Library/Scripts/removeTempAdmin.sh << EOS
# Delete the temp admin user
#sudo sysadminctl -deleteUser tempadmin
#sudo dscl . -delete /Users/tempadmin
sudo jamf deleteAccount -username tempadmin -deleteHomeDirectory
# Provide feedback to user
sudo osascript -e "display dialog \\"You administrative rights have ended.\\" with title \\"Temporary Admin Account\\" buttons {\\"OK\\"} default button \\"OK\\""
# Bootout the launch daemon
sudo launchctl bootout system /Library/LaunchDaemons/removeTempAdmin.plist
# Delete the daemon
sudo rm /Library/LaunchDaemons/removeTempAdmin.plist
EOSThe three account deletion commands fail in the script yet all work manually via CLI. Bootout now works but the daemon isn't deleted. If delete the daemon first that will work but then bootout fails.
Managed to develop this into a basic working solution using two scripts: one to create the temp admin account along with launch agents and daemons; and a second script to delete the temp admin account.
Works well but we're interested in a more feature rich commercial solution such as Elevate24 which includes MFA, improved logging and ongoing support.