Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Deleting user accounts created directly in NetInfo System
You cannot delete user accounts using the System Preferences "Accounts" pane unless the home folder of the user exists. This occurs in 10.2.6 and possibly under earlier versions.

If you have created users by editing Netinfo and then (without logging in as the user) try to delete them in the System Preferences pane, you will probably find that you cannot do so. A simple workaround is to log in as the user; this will create the home directory and you can then delete it.

Alternatively, create the home directory in the Terminal and try again.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[5,810 views]  

Deleting user accounts created directly in NetInfo | 13 comments | Create New Account
Click here to return to the 'Deleting user accounts created directly in NetInfo' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Deleting user accounts created directly in NetInfo
Authored by: CharlesVan on Jun 12, '03 12:34:12PM

What if you can't log in to that account anymore?

I have a user that I created for testing purposes and now I can't get rid of it in the Accounts pane. :(

I've already gone into root and deleted all the files (Home folder, etc.) associated with that user. Are you saying that may be the problem?



[ Reply to This | # ]
Deleting user accounts created directly in NetInfo
Authored by: aaronfaby on Jun 12, '03 12:37:21PM

Try this:

sudo niutil -destroy . /users/username

Obviously, replace username with the user you wish to delete.



[ Reply to This | # ]
A bit more thorough...
Authored by: gatorparrots on Jun 12, '03 01:05:02PM
#!/bin/sh

##
# rmuser
# This script will remove user accounts on OS X 10.2.x
# author: gatorparrots 
# problems or suggestions can be posted to the macfora.com OS X UNIX forum
#
# usage: rmuser [username]
##

if [ $# -eq 0 ]; then
  printf "usage: rmuser [username]\n"
  printf "User account and user's homedir will be irretrievably removed.\n" >&2
  exit 2
fi

username=$1

#safety checks
if [ "$username" = "root" ]; then
  echo "That's not a wise thing to do."
  exit 1
fi
if [ -z "`niutil -read . /users/$username 2> /dev/null `" ]; then
	echo "$username does not exit."
	exit 2
fi

# Need to be a sudoer to remove user
sudo -p "Please authenticate to remove user (administrator password): " printf "" || {
	echo "Abort: could not authenticate" >&2
	exit 1
}

userID=$(niutil -readprop . /users/$username uid)

#remove configuration files and other vestiges
if sudo [ -f /var/db/samba/hash/$username ]; then
    	sudo rm -f /var/db/samba/hash/$username
fi
if sudo [ -f "/etc/httpd/users/$username.conf" ]; then
		sudo rm -f "/etc/httpd/users/$username.conf"
fi
if [ -f "/Users/Deleted Users/$username.dmg" ]; then
		sudo rm -f "/Users/Deleted Users/$username.dmg"
fi
if sudo [ -f "/Library/Application Support/SyncService/$userID" ]; then
    	sudo rm -rf "/Library/Application Support/SyncService/$userID"
fi
if sudo [ -d /private/tmp/$userID ]; then
    	sudo rm -rf /private/tmp/$userID
fi
sudo rm -rf /.Trashes/$userID
sudo rm -rf /Volumes/*/.Trashes/$userID
sudo rm -f /Library/caches/*.$username
sudo rm -f /Library/caches/*.$userID
sudo rm -f "/Library/caches/Desktop Pictures/$username.*"

##You may wish to retain the user's homedir; if so, comment lines below 
userhome="`niutil -readprop . /users/$username home`"
sudo rm -rf $userhome

#remove admin status, if exists
sudo niutil -destroyval . /groups/admin users $username

#remove user
sudo niutil -destroy . /users/$username
sudo niutil -resync .

#reassign file ownership to main owner (501)
#comment out or change reassignment UID, if desired
sudo find / -user $userID -exec chown 501 {} \;

echo 'User account "'$username'" removed.'


[ Reply to This | # ]
GeekLog ate the backslash...
Authored by: gatorparrots on Jun 12, '03 01:16:17PM
Near the end of the script, the UID reassignment code should be: sudo find / -user $userID -exec chown 501 {} \;

[ Reply to This | # ]
GeekLog ate the backslash II
Authored by: gatorparrots on Jun 12, '03 01:17:50PM
sudo find / -user $userID -exec chown 501 {} \;

[ Reply to This | # ]
Deleting user accounts created directly in NetInfo
Authored by: CharlesVan on Jun 12, '03 07:39:46PM

Thanks for your help... but I must admit I'm afraid to go into the terminal to do anything. :( I don't know enough to try something so drastic. :)



[ Reply to This | # ]
Deleting user accounts created directly in NetInfo
Authored by: ssevenup on Jun 12, '03 12:52:11PM
This shell script will do it, and also find/kill all entries in groups.

#!/bin/sh

# Deletes users from commandline

NIUTIL="/usr/bin/niutil"
NIDUMP="/usr/bin/nidump"
CUT="/usr/bin/cut"
GREP="/usr/bin/grep"

if [ $USER != "root" ]; then
  echo "You must be root to execute this script."
  exit
fi

  echo -n "User to Destroy: "
  read uname
if [ "${uname}" = "root" ]; then
  echo "I wouldn't do that if I were you."
  exit
fi

if [ "${uname}" = "" ]; then
  echo "Please give me a valid username."
  exit
fi

if [ -z `NIDUMP passwd . | CUT -d: -f1 | GREP -x "${uname}"` ]; then
  echo "No such user found"
  echo ""
  exit 1
else
  NIUTIL -destroy . /users/"${uname}"
      declare -a gname
      gname=( `NIDUMP group . | GREP -w "${uname}" | cut -d: -f1` )
      while NIUTIL -destroyval . /groups/"${gname[0]}" users "${uname}" > /dev/null 2>&1
      do
        gname=( `NIDUMP group . | GREP -w "${uname}" | cut -d: -f1` )
        NIUTIL resync
      done
      echo "You may need to delete the home directory and symlinks"
      echo ""
fi

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.

[ Reply to This | # ]

Re:Deleting user accounts created directly in NetInfo
Authored by: kerbaugh on Jun 16, '03 07:09:29PM

Hi Mark,
   It may just be my browser, but aren't the dollar signs, "$" missing in front of all of the variables whose names are all in capital letters? By the way, while adherence to standards is generally lacking in the case of script return status, the correct code for ERROR_NON_ROOT_USER is 70, as in:

E_NON_ROOT_USER=70 # Must run as root.
ROOT_UID=0

if [ "$UID" -ne "$ROOT_UID" ]
then
   echo; echo "You must be root to run this script."; echo
   exit $E_NON_ROOT_USER
fi



[ Reply to This | # ]
Deleting user accounts created directly in NetInfo
Authored by: deleted_user18 on Jun 12, '03 02:33:37PM

Same for me, although my User had a home directory. There was a error message in Console (which I can't remember).

I deleted the home directory manually and the user in Netinfo database.

Anyway, Apple this stinks...



[ Reply to This | # ]
Deleting user accounts created directly in NetInfo
Authored by: Anonymous on Jun 12, '03 07:56:26PM

I think that the System Preferences Accounts panel only deletes the user if it sucessfully manages to archive the user's home directory. If this fails for any reason it doesn't delete the user. This prevents data loss.

However in this case the operation may fail because the directory isn't found. Hence the problem.

I don't actually know if this theory is correct, but it seems to fit the facts.




[ Reply to This | # ]
User 501 resists deletion
Authored by: zacht on Jun 13, '03 12:36:33AM
Speaking of times that System Prefs doesn't want to delete a user, I found recently that the first user I set up on a new Mac was a little hard to get rid of.

Well, I was supposed to be helping my family set up their new iMac, but instead I made a bit of a mess of it. Eventually we decided to make a new user and delete the users we had set up at the beginning, including the "original" user, with uid 501.

The System Prefs panel wouldn't delete the user. It kept archiving that user's home directory and putting up a success message, as if everything were hunky-dory, but the user was still there, could still log in, etc.

Eventually we went into NetInfo Manager and deleted it there. Then we struggled a bit with all the left-behind files belonging to user 501. Of course the whole thing is explained in the forums and we could have saved a lot of time... I'll never again do anything without checking the forums first!

http://forums.macosxhints.com/showthread.php?s=7abf86b3c035fafe68a654e3cbe87b47&threadid=12077

Zach

[ Reply to This | # ]

User 501 resists deletion
Authored by: kerbaugh on Jun 16, '03 09:07:24PM

Hi Zach,
   I thought about mentioning this in a number of places above but you signed your name, so I thought you wouldn't mind a comment that might be useful in general. Changing over files after deleting a user is still easy if you remember the UID (which can be obtained from any file owned by that user) and no user has that UID. With the following, you can change all files owned by that (former) user (say UID = 501) to be owned by username, and the user's group, :

sudo find / -user 501 -exec chown : {} \;

The idea is that find can search for a user's number even if there is no longer any such user. Thus name and number can be used together to advantage.
--
Gary



[ Reply to This | # ]
User 501 resists deletion
Authored by: zacht on Jun 17, '03 08:56:28AM

Thanks. In fact, that's mentioned in the forum article that I included a link to, but it never hurts to have it mentioned again!

Actually, though, I've started to wonder why the computer resisted deleting that user. Was it some weird thing with that specific computer, or is there something special about user 501? The computer seems to be running fine without a user 501. The user certainly had a home directory, so that wasn't the problem. It even managed to make a disk image backup of the home directory and put it into the "Deleted Users" folder.

Unfortunately, we didn't look at the system log. Oh, well.

--Zach



[ Reply to This | # ]