As the subject says, I'm trying to add a new user. When I run the command, it says the user already exists. But looking in /etc/passwd, /etc/group, and /etc/shadow shows that the user does not exist.
Running the command on my local machine works just fine. I'm running Ubuntu 11.10 on both.
Here's my terminal commands and output:
root@ws-prod-www-01:~# useradd -s /sbin/nologin -m -d /var/www/html/atc -g 33 -u 10141 atc
useradd: user 'atc' already exists
root@ws-prod-www-01:~# grep atc /etc/passwd
speech-dispatcher:x:111:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/sh
root@ws-prod-www-01:~# grep atc /etc/shadow
speech-dispatcher:!:15259:0:99999:7:::
root@ws-prod-www-01:~# grep atc /etc/group
root@ws-prod-www-01:~#
I also tried:
root@ws-prod-www-01:~# adduser --shell /sbin/nologin --home /var/www/html/atc --gid 33 --uid 10141 atc
Warning: The home dir /var/www/html/atc you specified already exists.
adduser: The user `atc' already exists.
root@ws-prod-www-01:~#
Any thoughts?
Is there any reason you are specifying the uid rather than letting the system choose one for you? You can see if your chosen id is in use by doing
grep '10141' /etc/passwd
. If that is the case then the error message is certainly a bit misleading :/It's also quite possible that your system recognises users who are not in
/etc/passwd
- for example by using LDAP. One quick way to test that is to doid atc
and see if the system recognises it. Another way would begetent passwd atc
which will also show you users the system recognises who are not in/etc/passwd
. Or you could again check if the uid is in use withgetent passwd 10141
. (You can also rungetent passwd
to get the full list of entries.) More about getent.To see where these users might come from you could look at
/etc/nsswitch.conf
(man page) - the line startingpasswd
will show you where your system is looking for users. Common default values arefiles
andcompat
, though more complex setups may have multiple values including values such asldap
,dns
andwinbind
.files
means the standard files including/etc/passwd
.I'm not so clear on the exact meaning of
compat
, but my reading of thensswitch.conf
man page suggests it is a combination offiles
andnis
.nis
is the Network Information Service which is largely superceded these days but may affect your system.Try typing the following in a terminal
This should remove all instances of the user
In my case, /etc/nsswitch.conf had this for passwd:
The user was in Active Directory, so winbind was seeing an 'existing" user account in AD.
Then running useradd allowed me to add the user account.
As one of the above answer suggested, take a look at your NSS library file /etc/nsswitch.conf to check if system search for a user in LDAP kind of setup. If so, you can do one of the following action to fix the problem:
Remove the user from ldap server.
Remove the ldap reference from the /etc/nsswitch.conf file so that NSS library dont look for the user in ldap server.
Keep the user in the ldap as it is, but create the same user in the system using luseradd command.
luseradd myuser
Take a look at this article https://www.easyaslinux.com/quick-fix/user-already-exists-error-when-user-doesnt-exist-on-the-system/ for detailed steps.