Apple - When I open Terminal, I get an "I have no name!" prompt

Something in memory got corrupted, and the mapping between your userID (502) and your username (ipd) was lost. I've seen it happen (usually when I've manually killed hung system processes), although I'm not sure exactly what causes it. launchd maybe?

Because that mapping is lost, whoami can't convert your ID into a username so returns the ID, and your prompt defaults to the "I have no name!" message because you effectively don't have a name.

Logging out and back in might fixit, but restarting is the best way (as you discovered).

Basically, it's a symptom of another problem, and not a problem in and of itself.

I see it's an old thread, but here is the solution to this problem (without restarting the whole computer).

The problem is in the opendirectoryd daemon and the earliest reports date from the beginning of 2011. Restarting the daemon (switching users with an admin one via Fast User Switching) fixes the problem.

While writing this answer, I've found a similar question in the Serverfault here, which also covers my answer.

This happens to me randomly when I resume from standby (i.e. opening my laptop). A log out or reboot is the only way for me to fix it. I don’t know exactly what causes it. As I type it is happening right now. As the comment in the original post asked, I ran id -p and it crashed. (Crash report:

Console commands:

whoami — returns 501

id -p — crashes

cat /etc/passwd — my user is not in the document.

Any ssh attempt fails with the error:

You don't exist, go away!

I also checked out the console, from waking up, a bunch of random "Socket not connected" errors appear (which I think might be normal, being that wireless doesn’t connect immediately) from programs like Dropbox. An interesting error appears though:

4/12/12 8:37:09.045 PM coreservicesd: _scserver_ServerCheckin: client uid validation failure; getpwuid(501) == NULL

4/12/12 8:37:09.400 PM coreservicesd: _scserver_ServerCheckin: client uid validation failure; getpwuid(501) == NULL

Still not sure what is causing it, but thought I would share these diagnostics.

I’m on a Mid 2009 MacBook Pro with 10.7.3 installed.