git error "unable to look up current user in the passwd file: no such user" - what does this mean?
Solution 1
It turns out this was "fixed" in 2.6.5 -- no longer requiring a proper identification for many git operations.
Here's the commit in question.
The gist of the commit:
ident: loosen getpwuid error in non-strict mode
If the user has not specified an identity and we have to turn to getpwuid() to find the username or gecos field, we die immediately when getpwuid fails (e.g., because the user does not exist). This is OK for making a commit, where we have set IDENT_STRICT and would want to bail on bogus input.
But for something like a reflog, where the ident is "best effort", it can be pain. For instance, even running "git clone" with a UID that is not in /etc/passwd will result in git barfing, just because we can't find an ident to put in the reflog.
Instead of dying in xgetpwuid_self, we can instead return a fallback value, and set a "bogus" flag. For the username in an email, we already have a "default_email_is_bogus" flag. For the name field, we introduce (and check) a matching "default_name_is_bogus" flag. As a bonus, this means you now get the usual "tell me who you are" advice instead of just a "no such user" error.
The new xgetpwuid_self
is now implemented as follows:
static struct passwd *xgetpwuid_self(int *is_bogus)
{
struct passwd *pw;
errno = 0;
pw = getpwuid(getuid());
if (!pw) {
static struct passwd fallback;
fallback.pw_name = "unknown";
#ifndef NO_GECOS_IN_PWENT
fallback.pw_gecos = "Unknown";
#endif
pw = &fallback;
if (is_bogus)
*is_bogus = 1;
}
return pw;
}
Solution 2
This error message is returned by wrapper.c
:
struct passwd *xgetpwuid_self(void)
{
struct passwd *pw;
errno = 0;
pw = getpwuid(getuid());
if (!pw)
die(_("unable to look up current user in the passwd file: %s"),
errno ? strerror(errno) : _("no such user"));
return pw;
}
That means the common library getpwuid
function doesn't find a password entry in /etc/passwd for the user account under which the git process is called
It is like the nscd service didn't know how to resolve some services.
Ask your admin to double-check the account jail directory (let's call it $D
), as illustrated in this article. Especially its $D/etc
folder:
cp -fv /etc/{group,prelink.cache,services,adjtime,shells,gshadow,shadow,hosts.deny,localtime,nsswitch.conf,nscd.conf,prelink.conf,protocols,hosts,passwd,ld.so.cache,ld.so.conf,resolv.conf,host.conf} $D/et
Solution 3
The issue is that git doesn't recognise your identity. This is due to the missing .gitconfig file which should be present in your home directory. (Just do ls -la ~ to verify that it is missing)
Fix:
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "[email protected]"
This would generate that file and resolve the error.
C. S.
Updated on July 25, 2022Comments
-
C. S. almost 2 years
I cloned my git repo to a remote server, using ssh to communicate with it. Using
git fetch remote
works, but when I typegit push remote
I get this output:Counting objects: 242, done. Delta compression using up to 4 threads. Compressing objects: 100% (184/184), done. Writing objects: 100% (215/215), 238.00 KiB | 0 bytes/s, done. Total 215 (delta 58), reused 0 (delta 0) fatal: unable to look up current user in the passwd file: no such user fatal: The remote end hung up unexpectedly fatal: The remote end hung up unexpectedly
My server admin says that my ssh user is configured inside a chroot-jail. What could be done to solve this error?
-
C. S. over 10 yearsThanks for answer. The admin has done all this, but still it's not working. Is there any log file which tells me which user is needed at all so he can put this user into /etc/passwd ?
-
VonC over 10 years@C.S. on the client side, you can push with trace activated for having a bit more clues:
GIT_TRACE=1 git push
. On the server side, it depends on the url used for the remote: https or ssh. But looking at the logs of the server (Apache or sshd) involved can help too. -
Eugene over 8 yearsThis method used to fill default user's identity, to avoid using it you can set your identity manually:
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
I got this issue when I had user authenticated via remote LDAP, so I had no entry in passwd file -
Pablo Halpern over 5 yearsI found that I could get around the problem without involving the administrator (which is a lengthy process) by editing the .git/config file and putting my username@ before the server name in the URL field of the offending remote.