If you force there to exist multiple users with the same username, then there will be multiple entries in /etc/{shadow,passwd}
with the same name:
$ cat /etc/passwd
...
a:x:1001:1002::/home/a:/bin/bash
a:x:1002:1003::/home/b:/bin/bash
# cat /etc/shadow
a:...:17702:0:99999:7:::
a:...:17702:0:99999:7:::
If you try to log in as that user, you'll log in as the first match.
$ ssh a@<host>
Password:
$ id
uid=1001(a) gid=1002(a) groups=1002(a)
$ pwd
/home/a
There will be no way to log in as the second user with the same name.
Note that Linux tracks users by their uid, not by their username.
It would be possible, however, to have two different usernames be the same user ID. Consider a different version of /etc/passwd
:
$ cat /etc/passwd
...
a:x:1001:1002::/home/a:/bin/bash
b:x:1001:1002::/home/b:/bin/bash
Note that for both usernames a
and b
, the third column is 1001 -- that's the uid / user ID. Now, if user a
or user b
logs in (even with different passwords), they'll both be "user 1001", and show as user a
from the OS' perspective. Here too, the first matching entry is the one returned (in most cases):
$ ssh a@host
Password: <a's password>
$ id
uid=1001(a) gid=1002(a) groups=1002(a)
$ ssh b@host
Password: <b's password>
$ id
uid=1001(a) gid=1002(a) groups=1002(a)
Both a
and b
are uid 1001
and will have access to the resources available to uid 1001
.
ls -n
. – DopeGhoti Jun 20 '18 at 21:10/home/old-arch
before reinstalling the system (I have/home
on its own partition and I don't format it), so that I could then have a new, pristine/home/arch
. I wondered whether I would retain the same permissions on my files, or if the system would recognize me as a differentarch
. – Arch Stanton Jun 20 '18 at 21:17root
andtoor
in the BSDs. – user Jun 21 '18 at 13:39