Skip to main content
Solved

Remove Current User as Admin

  • April 12, 2022
  • 6 replies
  • 44 views

Forum|alt.badge.img+3
  • New Contributor

Hi,

 

I want to remove the current login user as admin and I tried this command and it seems not to working.

 

#!/bin/bash

/usr/sbin/dseditgroup -o edit -d "$currentUser" -t user admin

 

is anyone can help me with this?

Thank you

Best answer by MacJunior

#!/bin/sh

loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

dseditgroup -o edit -d $loggedInUser -t user admin

 

Give it a shot

6 replies

MacJunior
Forum|alt.badge.img+9
  • Valued Contributor
  • Answer
  • April 12, 2022

#!/bin/sh

loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

dseditgroup -o edit -d $loggedInUser -t user admin

 

Give it a shot


rabbitt
Forum|alt.badge.img+17
  • Valued Contributor
  • April 12, 2022

It's also possible the admin user is the only administrator account on the machine that has a FileVault securetoken.  macOS restricts you from deleting that user even if there's some other mechanism to hand out securetokens to users like a valid bootstrap token being stored in the MDM server or Jamf Connect installed to make more user accounts.

You'd need to elevate another user temporarily to an admin account, delete the user, and then demote the temporary admin...


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • April 13, 2022

#!/bin/sh

loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

dseditgroup -o edit -d $loggedInUser -t user admin

 

Give it a shot


unfortunately it does not work 


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • April 13, 2022

It's also possible the admin user is the only administrator account on the machine that has a FileVault securetoken.  macOS restricts you from deleting that user even if there's some other mechanism to hand out securetokens to users like a valid bootstrap token being stored in the MDM server or Jamf Connect installed to make more user accounts.

You'd need to elevate another user temporarily to an admin account, delete the user, and then demote the temporary admin...


the macs has another admin account which is why i want to revoke the other one (the current login user). 

 

i manage to found this command  but i cant do a whitelist of the admin account according to the username since different set of macs have different admin username


MacJunior
Forum|alt.badge.img+9
  • Valued Contributor
  • April 13, 2022

unfortunately it does not work 


I tried it on a test machine and it works !! what does it say in the logs of that policy?


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • April 18, 2022

I tried it on a test machine and it works !! what does it say in the logs of that policy?


i recreate back the script & policy and it works now. thank you