10

When I run whoami it says:

whoami: cannot find name for user id 0

My /etc/passwd file looks like this:

root::0:0:root:/root:/bin/bash
7
  • Your /etc/passwd is broken? Can you post the contents
    – daisy
    Commented Jan 31, 2013 at 2:06
  • What's your id command in current shell when you get whoami?. Commented Jan 31, 2013 at 3:16
  • 7
    (1) Which linux distribution? (2) What is output of pwck and grpck? (3) Does file /etc/shadow exist?
    – John Siu
    Commented Jan 31, 2013 at 4:34
  • 5
    Also, have you set up (or attempted to) directory services of some sort (LDAP, NIS, etc.)? Have you touched /etc/nsswitch.conf?
    – derobert
    Commented Jan 31, 2013 at 17:09
  • 1
    I'm thinking nsswitch.conf as derobert mentioned. But I have seen nscd cause weird crap like this before. If it's running, try stopping it. If it is not running, try starting it (though the starting it if it's not running thing was an old RHEL bug that should not around any more).
    – phemmer
    Commented Feb 1, 2013 at 3:35

5 Answers 5

9

just say my experience
// after check /etc/passwd, /etc/shadow

0. problem

on broken device:

cat /etc/passwd
root:x:0:0:root:/root:/bin/bash

and

whoami
whoami: cannot find name for user ID 0

on normal device:

whoami
root

1. research

try to find the reason:

strace whoami 2>&1 | grep -E '/etc|/lib'
...
open("/lib/arm-linux-gnueabi/libnss_compat.so.2", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libnsl.so.1", O_RDONLY) = 3
open("/etc/ld.so.cache", O_RDONLY)      = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libnss_nis.so.2", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libnss_files.so.2", O_RDONLY) = 3
open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3

found it need those *.so:

/lib/arm-linux-gnueabi/libnss_compat.so.2
/lib/arm-linux-gnueabi/libnsl.so.1
/lib/arm-linux-gnueabi/libnss_nis.so.2
/lib/arm-linux-gnueabi/libnss_files.so.2

//all come from libc6 package, i work with arm linux device.

2. solution

i copy them to the broken device, then whoami worked right,

and bash prompt I have no name!@localhost got fixed.

8

I would recommend checking the permissions on /etc/passwd and /etc/group. If they're not set to 644 (-rw-r--r--), then run:

chmod 644 /etc/passwd; chmod 644 /etc/group

1
  • still says cannot find name for user id 0
    – gabemai
    Commented Jan 31, 2013 at 22:28
7

Notice there is a missing x

This is the content of mine on Linux Mint with kernel 3.8.0-35-generic

root:x:0:0:root:/root:/bin/zsh

The x means that the actual password information is being stored in a separate shadow password file, tipically /etc/shadow

https://en.wikipedia.org/wiki/Passwd

1

Check that each and every line in /etc/passwd has exactly seven fields.

-1

I know it's right on time, but the reason could be coreutils compiled without ACL support. Check it and rebuild the package if needed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .