git push to remote repository “Could not read from remote repository”

后端 未结 4 1051
说谎
说谎 2020-12-03 06:52

I searched for a while but I can\'t find a solution to my Problem.

I have a Server I can connect to via ssh with the username git and a local git reposi

相关标签:
4条回答
  • 2020-12-03 07:14

    You can also check your SSH identities by doing:

    $ ssh-add -L
    

    I had a similar problem. There was a wrong key in my identities, don't remember why. I just delete all my identities (maybe you will need to add keys again):

    $ ssh-add -D  
    

    Then I did push/pull without problems.

    0 讨论(0)
  • 2020-12-03 07:16

    I personally had 2 different issues with this:

    1. plink (which is used by git on Windows) does not accept id_rsa private key as it is in OpenSSH 2 format => I had to convert it (using puttygen) to PuTTY own .ppk format and attach via Git Extensions "Remotes" dialog

    2. I specified the path to git folder wrongly, 'cause my ssh session was chrooted (It might be wrong word) and I specified that what was my FTP "root" as "/", while it was "/home/www/username/" instead.

    I understood all this, using GIT TRACE=2 as described above and also by using procmon to determine the exact command-line for plink and then playing with it, adding "-v" option ("verbose").

    0 讨论(0)
  • 2020-12-03 07:20

    In this case, using openssh over putty was key.


    Original answer (tips for debugging)

    I can log in via ssh with the git user.

    That means this works:

    ssh git@serverIp
    

    You do have a HOME variable defined, and ssh public/private keys (id_rsa / id_rsa.pub) in %HOME%/.ssh/.

    This question suggests a different url:

    git remote set-url test git@serverIp:/home/git/test.git
    

    Make sure you did create your git repo as git (and not as root, when you created the git account, as in this question).
    ssh git@serverIp "which git" should return the path of the git executable.

    Check also that all parent directories have the relevant x (execute) bit set for the user git or the group gitgroup, running ls -ld /home /home/git /home/git/test.git.
    Also, getting more info for a git command can be done with:

    • git push --verbose
      or:
    • GIT_TRACE=2 git push test master

    If you have a private ssh key with a password, it would be best to first test those ssh commands with a private ssh key not password-protected, to see if the issue persists.
    Or, you can keep that password-protected ssh key, but double-check your .bashrc as in this answer.


    For any ssh connection issue (where git's password is needed), check:

    • /var/log/auth.log,
    • an sshd debug session

    In your case, since it works with ssh git@serverIp (interactive secure shell), but not with git (which opens a non-interactive secure shell), have a look at this thread, which references this one:

    When ssh is started with a commandline, a non-interactive non-login shell is started.
    However...bash does not use $BASH_ENV in this case, so setting it in ~/.ssh/environment (e.g. to /etc/profile) doesn't help.
    What bash does is source /etc/bashrc and ~/.bashrc.

    Make sure that /etc/profile does define the path for git, since a non-login account could be used here (that seems to be the case here, since ssh git@serverIp "which git" worked, and ssh git@serverIp "git --version" should too).

    But check also the right issue, and test a chmod 755 on /home, /home/git and /home/git/test.git.

    0 讨论(0)
  • 2020-12-03 07:26

    Set GIT_SSH environment variable to the full path of TortoisePlink.exe (you may have to download TortoiseGit for this) instead of PuTTY's plink.exe. This will allow for popup dialog window to prompt for things, i.e., confirm fingerprint, or enter password. If you use plink.exe through Git, you cannot type in responses to plink.exe prompts, which if there are any prompts will cause the fatal error you saw.

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