33

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 repository.
Now I want to push my local repository to a newly created one on the Server.

Here is what I did:

  • created a git repository in /home/git/test.git
  • initialized the repository as bare
  • added the remote repository on the local machine
    git remote add test ssh://git@serverIp:/home/git/test.git
  • now I executed the push command:
    git push test master

I always get the

fatal: could not read from remote repository

Please make sure you have the correct access rights
and the repository exists.

I am working on a local windows 7 machine and want to upload to a linux server.
I can log in via ssh with the git user. I also tried to do this as the root user(to get things to work once) with the same result.
I never get asked for the ssh password.

I really don't know what I am doing wrong.
Before you call this a duplicate, I searched a lot for this problem and none seemed to talk about the same problem.

update:

  • "which git" returns /usr/bin/git
  • PATH echo includes /usr/bin
  • id_rsa and id_rsa.pub files are all set up and withput Passphrase
  • ssh git@serverIp which git-receive-pack works too and returns /usr/bin/git-receive-pack
  • ssh git@serverIp ls /home/git/test.git works
  • all relevant directories are chmod 755
  • git is owner of the repository
  • auth.log file gets no new entries on tried push command
  • GIT_TRACE=2 git push test master returns:

    'C:\Program Files (x86)\PuTTY\plink.exe' '-batch' 'git@serverIp' 'git-receive-pack '\''/home/git/test.git'\''' fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

user1090755
  • 517
  • 1
  • 4
  • 14
  • plink? Could you try it with openssh? (http://stackoverflow.com/a/7697167/6309, http://guides.beanstalkapp.com/version-control/git-on-windows.html) – VonC Apr 20 '13 at 22:57
  • 2
    What the, What just happened? It works I just reinstalled Git choosing openssh instead of putty and it push without problem to the remote repository. – user1090755 Apr 20 '13 at 23:28
  • Right, I didn't see plink right away, but I always use openssh with my git installation. I have updated the answer. – VonC Apr 20 '13 at 23:30
  • Well they should remove plink from the list of choices if it reduces the functionality. Well thank you very much I used days on this Problem. – user1090755 Apr 20 '13 at 23:49
  • One reason might be the wrong ownership/mode for your home directory. I got `Authentication refused: bad ownership or modes for directory /home/data/users/okopp`. – koppor Feb 24 '14 at 19:18

4 Answers4

17

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:


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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 3
    It turns out the `ssh://` url is [supported as well](http://git-scm.com/book/ch4-1.html#The-SSH-Protocol), but it's specified wrong by the OP. `ssh://git@serverIp:/home/git/test.git` is invalid because of the extra colon. It should be `ssh://git@serverIp/test.git` or, as you suggest, `git@serverIP:/home/git/test.git` or `git@serverIp:test.git`. – John Szakmeister Apr 20 '13 at 11:38
  • i have the key set up in .ssh, I tried every version of url, i made sure git is the owner of test.git and test.git has execute bit set. verbose only give the additional "pushing to "url" message. Oh and i added the suggested script in the .bashrc – user1090755 Apr 20 '13 at 12:10
  • @user1090755 is your private ssh key password protected? – VonC Apr 20 '13 at 12:12
  • i entered a passphrase yes, but just now i created a new one with none. BTW "which git" asks for the git user password and then returns me the git executable path. – user1090755 Apr 20 '13 at 12:18
  • @user1090755 `ssh git@serverIP` should not ask you for `git`'s password, or that just means ssh keys aren't working properly. You can know more by looking at `/var/log/auth.log`, or making one `sshd` debug session (http://serverfault.com/questions/130482/how-to-check-sshd-log) – VonC Apr 20 '13 at 12:21
  • You can also try using `GIT_TRACE=2 git push test master` might give useful information as well. – John Szakmeister Apr 20 '13 at 12:40
  • @user1090755 jszakmeister mentioned an additional debug advice, but forgot the `@` notification syntax. `GIT_TRACE=2 git push test master` – VonC Apr 20 '13 at 12:52
  • @VonC Thanks. I forget the OP isn't necessarily notified when a comment is made. – John Szakmeister Apr 20 '13 at 13:16
  • okay so now ssh git@serverIp does not ask for a password anymore and the additional information reports this: trace: built-in: git 'push' 'test' 'master' trace: run_command: 'C:\Program Files (x86)\PuTTY\plink.exe' '-batch' 'git@serverIp' 'git-receive-pack '\''/home/git/test.git'\''' fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. – user1090755 Apr 20 '13 at 13:30
  • @user1090755 it could be because git would use a non-login account, which might not have the right to access your git repo. see my edit. – VonC Apr 20 '13 at 13:45
  • hmm so i checked /etc/profile and PATH includes /usr/bin with "which git" returning /usr/bin/git. I also tried editing the other three files mentioned in your source to no avail. Oh and chmod 755 for all three directories also changed nothing – user1090755 Apr 20 '13 at 14:34
  • @user1090755 and a `ssh git@serverIp which git-receive-pack` works too? – VonC Apr 20 '13 at 14:35
  • @user1090755 then it should be a right access issue. Does this work? `ssh git@serverIp ls /home/git/test.git` (replace `test.git` with your bare repo directory) – VonC Apr 20 '13 at 14:39
  • @user1090755 can you clone it first, make a commit locally and push it? Does a `git clone ssh://git@serverIP:/home/git/test.git` work? – VonC Apr 20 '13 at 14:44
  • no i can't clone reports the same fatal Error as pushing to it – user1090755 Apr 20 '13 at 14:47
  • @user1090755 ok, but what does return `ssh git@serverIp echo \$PATH` though? – VonC Apr 20 '13 at 15:07
  • I already did that and it just returns what is specified in the profile /usr/local/bin:/usr/bin:/bin:/usr/bin/x11:/usr/games – user1090755 Apr 20 '13 at 15:10
  • @user1090755 so a non-interactive session has the right path and access rights... but it still fails? Frustrating! Beside some kind of firewall/anti-virus issue, I am a bit at a loss. Cloning directly on the server works, right? – VonC Apr 20 '13 at 15:14
  • cloning on the Server works just get a warning that i seem to have cloned an empty repository – user1090755 Apr 20 '13 at 15:16
  • @user1090755 when cloning form the client (windows 7), any clue in the `/var/log/auth.log` file (sshd logs)? I'll be back in 90 minutes for more suport – VonC Apr 20 '13 at 15:19
8

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.

Matias
  • 575
  • 5
  • 17
  • Great answer..... you saved my time...I was getting pissed off since last one hour...tried all other stuff.. – minhas23 Jul 29 '16 at 10:42
7

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").

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
62mkv
  • 1,444
  • 1
  • 16
  • 28
0

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.

konyak
  • 10,818
  • 4
  • 59
  • 65