How can I delete a duplicate user via the command line in OS X?
dscl
is the command line utility to maintain OSX's user/group databases. To explore what's there, sudo dscl .
to get its command line, then list /Users
. To see the definition for a given user, use read /Users/admin
. As you might expect, removing it is delete /Users/admin
. (There's also a help
command.)
For scripting, you can do these from the command line:
$ sudo dscl . -read /Users/admin
That is, just add a -
before the command name.
I'm pretty sure DirectoryService names must be unique, so I assume that your existing admin
is admin
and the bogus one must be admin␣
or something silly like that. Alternately, you might have one defined in /etc/passwd
and one in DirectoryServices; the former will only be used during system boot, before /usr/sbin/DirectoryService
is running.
Related videos on Youtube
smory
MacLinuxSysAdminWordPressTwitterHumo[u]rGeekStephensonMUDsButNotWoW phew!
Updated on September 17, 2022Comments
-
smory over 1 year
I accidentally force-created a user with the shortname "admin" after my Mac OS X machines already had users with the shortname "admin". What possible remedies are available to me in order to delete all traces of that second, spurious "admin" user?
(Ideally, this would be a command-line op because it needs to be repeated across the multitude of machines that now have an extra "admin".)
-
smory about 13 yearsI'm aware of dscl and have examined the users -- they are identical with the exception of GeneratedUID.
-
geekosaur about 13 yearsLooks like you can include that GeneratedUUID to select the specific record.
dscl . -delete /Users/admin GeneratedUUID mumble
.