When creating user with --create-home, for example this way:
# useradd -m test1 ; useradd -m test1
useradd: user 'test1' already exists
# grep test1 /etc/passwd
test1:x:1097:1097::/home/test1:/bin/sh
# stat -c '%u %U' /home/test1
1097 test1
second useradd failed, ownership is OK
but if for some reason two processes try to create the same user simultanuosly, there is a race condition:
# useradd -m test2 & useradd -m test2
useradd: warning: the home directory /home/test2 already exists.
useradd: Not copying any file from skel directory into it.
# grep test2 /etc/passwd
test2:x:1099:1099::/home/test2:/bin/sh
# stat -c '%U' /home/test2
1098 UNKNOWN
ownership is bad, because uid is wrong
Tested on:
ubuntu 22.04
ubuntu 24.04
ubuntu 26.04
I have local only installation, no ldap or something like that
egrep '(passwd|group|shadow)' /etc/nsswitch.conf
passwd: files systemd
group: files systemd
shadow: files systemd
gshadow: files systemd
When creating user with --create-home, for example this way:
second useradd failed, ownership is OK
but if for some reason two processes try to create the same user simultanuosly, there is a race condition:
ownership is bad, because uid is wrong
Tested on:
ubuntu 22.04
ubuntu 24.04
ubuntu 26.04
I have local only installation, no ldap or something like that
egrep '(passwd|group|shadow)' /etc/nsswitch.conf
passwd: files systemd
group: files systemd
shadow: files systemd
gshadow: files systemd