1

I have access to a system where two users have an UID 0:

host:~ # cat -n /etc/passwd | grep -E "root|testuser"
     1  root:x:0:0:root:/root:/bin/bash
    31  testuser:x:0:0:testuser:/root/testuser:/bin/bash
host:~ #

For example this often causes a behavior where I SSH(key-based auth) into this system with user name testuser and I'm identified as root:

host:~ # id
uid=0(root) gid=0(root) groups=0(root)
host:~ # ls -ld /root/testuser
drwxr-xr-x 3 root root 352 Jan 25 01:02 /root/testuser
host:~ #
host:~ # ls -ld /root/testuser/.ssh/
drwx------ 2 root root 80 Nov 18 15:38 /root/testuser/.ssh/
host:~ # 

However, in the middle of the login session I'm sometimes identified as testuser:

host:~ # ls -ld /root/testuser
drwxr-xr-x 3 testuser root 352 Dec 16 18:39 /root/testuser
host:~ #

This doesn't bother me, but I'm puzzled how is it possible that I can always SSH into this machine as a testuser while such duplicated UIDs setup should also mess up the ownership of the /root/testuser/.ssh/ directory and /root/testuser/.ssh/authorized_keys file.

  • 1
    Instead of giving two users uid 0, I'd strongly recommend having only root as uid 0, giving each of the administrators their own uid, and adding them to groups and sudoers (allowrd to execute as root) as appropriate. – dirkt Jan 25 '17 at 9:21
5

There is no such thing as “multiple users have a same UID”. A UID identifies a user. Same UID, same user.

What you have created is two different ways for the same user to log in. The user is UID 0. UID 0 can log in under the name root, with the password defined in the root entry of /etc/shadow, and when those credentials are used the HOME environment variable is set to /root and the program /bin/bash runs. UID 0 can also log in under the name testuser, with the password defined in the testuser entry of /etc/shadow, and when those credentials are used the HOME environment variable is set to /root/testuser and the program /bin/bash runs.

The kernel only knows about the user ID, not about the user name. The filesystem only stores the user ID, not the user names. User names are not used for access control to system objects such as files and processes. Most programs convert user IDs to user names when they need to display information involving a user, and from user names to user IDs when they need to implement some policy involving a user.

The files you looked at belong to user 0. When you run ls, it receives the information that the file's owner is 0, and it retrieves the information about user 0 in order to display it in a more friendly way. This normally returns the first entry in /etc/passwd, I can't explain why you're seeing testuser occasionally.

Many tools implicitly assume that there is a one-to-one correspondence between user names and user IDs, so the behavior if a user has multiple names is not always optimal. You aren't really supposed to do this; it'll mostly work but you need to be prepared to cope with the occasional oddity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.