Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git error "unable to look up current user in the passwd file: no such user" - what does this mean?

Tags:

git

git-push

ssh

I cloned my git repo to a remote server, using ssh to communicate with it. Using git fetch remote works, but when I type git 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?

like image 815
C. S. Avatar asked Nov 28 '13 17:11

C. S.


2 Answers

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;
}
like image 80
Anthony Sottile Avatar answered Oct 22 '22 08:10

Anthony Sottile


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
like image 36
VonC Avatar answered Oct 22 '22 07:10

VonC