fatal: could not read Username for 'https://github.com': No such file or directory

前端 未结 17 1272
自闭症患者
自闭症患者 2020-12-02 18:13

I have the following problem when I try to pull code using git Bash on Windows:

fatal: could not read Username for \'https://github.com\': No such file or dir         


        
相关标签:
17条回答
  • 2020-12-02 18:31

    I fixed this by installing a newer version of Git. The version I installed is 2.10.2 from https://git-scm.com. See the last post here: https://www.bountysource.com/issues/31602800-git-fails-to-authenticate-access-to-private-repository-over-https

    With newer Git Bash, the credential manager window pops up and you can enter your username and password, and it works!

    0 讨论(0)
  • 2020-12-02 18:31

    TL;DR: check if you can read/write to /dev/tty. If no and you have used su to open the shell, check if you have used it correctly.

    I was facing the same problem but on Linux and I have found the issue. I don't have my credentials stored so I always input them on prompt:

    Username for 'https://github.com': foo
    Password for 'https://foo@github.com': 
    

    The way how git handles http(s) connections is using /usr/lib/git-core/git-remote-https you can see strace here:

    stat("/usr/lib/git-core/git-remote-https", {st_mode=S_IFREG|0755, st_size=1366784, ...}) = 0
    pipe([9, 10])                           = 0
    rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
    clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f65398bb350) = 18177
    rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
    close(10)                               = 0
    read(9, "", 8)                          = 0
    close(9)                                = 0
    close(5)                                = 0
    close(8)                                = 0
    dup(7)                                  = 5
    fcntl(5, F_GETFL)                       = 0 (flags O_RDONLY)
    write(6, "capabilities\n", 13)          = 13
    fstat(5, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
    read(5, "fetch\noption\npush\ncheck-connecti"..., 4096) = 38
    write(6, "option progress true\n", 21)  = 21
    read(5, "ok\n", 4096)                   = 3
    write(6, "option verbosity 1\n", 19)    = 19
    read(5, "ok\n", 4096)                   = 3
    stat(".git/packed-refs", {st_mode=S_IFREG|0664, st_size=675, ...}) = 0
    lstat(".git/objects/10/52401742a2e9a3e8bf068b115c3818180bf19e", {st_mode=S_IFREG|0444, st_size=179, ...}) = 0
    lstat(".git/objects/4e/35fa16cf8f2676600f56e9ba78cf730adc706e", {st_mode=S_IFREG|0444, st_size=178, ...}) = 0
    dup(7)                                  = 8
    fcntl(8, F_GETFL)                       = 0 (flags O_RDONLY)
    close(8)                                = 0
    write(6, "list for-push\n", 14)         = 14
    read(5, fatal: could not read Username for 'https://github.com': No such device or address
    "", 4096)                       = 0
    --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=18177, si_uid=1000, si_status=128, si_utime=6, si_stime=2} ---
    exit_group(128)                         = ?
    +++ exited with 128 +++
    

    So I tried to call it directly:

    echo "list for-push" | strace /usr/lib/git-core/git-remote-https my
    

    and the result:

    poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 1 ([{fd=3, revents=POLLIN|POLLRDNORM}])
    recvfrom(3, "\27\3\3\1\32", 5, 0, NULL, NULL) = 5
    recvfrom(3, "\307|4Q\21\306\334\244o\237-\230\255\336\25\215D\257\227\274\r\330\314U\5\17\217T\274\262M\223"..., 282, 0, NULL, NULL) = 282
    openat(AT_FDCWD, "/dev/tty", O_RDONLY)  = -1 ENXIO (No such device or address)
    openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 4
    fstat(4, {st_mode=S_IFREG|0644, st_size=2995, ...}) = 0
    read(4, "# Locale name alias data base.\n#"..., 4096) = 2995
    read(4, "", 4096)                       = 0
    close(4)                                = 0
    openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
    openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
    openat(AT_FDCWD, "/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
    openat(AT_FDCWD, "/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
    write(2, "fatal: could not read Username f"..., 83fatal: could not read Username for 'https://github.com': No such device or address
    ) = 83
    exit_group(128)                         = ?
    +++ exited with 128 +++
    

    And here it came to me:

    openat(AT_FDCWD, "/dev/tty", O_RDONLY)  = -1 ENXIO (No such device or address)
    ...
    write(2, "fatal: could not read Username f"..., 83fatal: could not read Username for 'https://github.com': No such device or address
    ) = 83
    

    git-remote-https tries to read credentials via /dev/tty so I tested if it works:

    $ echo ahoj > /dev/tty
    bash: /dev/tty: No such device or address
    

    But in another terminal:

    # echo ahoj > /dev/tty
    ahoj
    

    I knew I switched to this user using su so I exited the shell to see how and found out I used command su danman - so I tested it again:

    ~# su danman -
    bash: cannot set terminal process group (-1): Inappropriate ioctl for device
    bash: no job control in this shell
    /root$ echo ahoj > /dev/tty
    bash: /dev/tty: No such device or address
    

    I probably ignored the message and continued working but this was the reason. When I switched using the correct su - danman everything worked fine:

    ~# su - danman
    danman@speedy:~$ echo ahoj > /dev/tty
    ahoj
    

    After this, git started working correctly

    0 讨论(0)
  • 2020-12-02 18:32

    This is an issue with your stored credentials in the system credential cache. You probably have the config variable 'credential.helper' set to either wincred or winstore and it is failing to clear it. If you start the Control Panel and launch the Credential Manager applet then look for items in the generic credentials section labelled "git:https://github.com". If you delete these, then the will be recreated next time but the credential helper utility will ask you for your new credentials.

    0 讨论(0)
  • 2020-12-02 18:33

    For me nothing worked from suggested above, I use git pull from jenkins shell script and apparently it takes wrong user name. I spent ages before I found a way to fix it without switching to SSH.

    In your the user's folder create .gitconfig file (if you don't have it already) and put your credentials in following format: https://user:pass@example.com, more info. After your .gitconfig file link to those credentials, in my case it was:

    [credential] helper = store --file /Users/admin/.git-credentials

    Now git will always use those credentials no matter what. I hope it will help someone, like it helped me.

    0 讨论(0)
  • 2020-12-02 18:35

    I faced the exact same problem. This problem occurred when I cloned using HTTPS URL and then tried to push the changes using Git Bash on Windows using:

    git clone https://github.com/{username}/{repo}.git
    

    However, when I used SSH URL to clone, this problem didn't occur:

    git clone git@github.com:{username}/{repo}.git
    
    0 讨论(0)
  • 2020-12-02 18:36

    What worked for me is to change the access of the Git repository from private to public.

    0 讨论(0)
提交回复
热议问题