3

I cannot clone or push to a repository on my server.

I have a bare repo that is located is a directory user@host in directory home/user/test.git that I am trying to access via git clone. I used ssh-add <pathtokey> to add my ssh key. It asked me for the passphrase. I can then ssh user@host successfully.

However if I then try to git clone ssh://user@host/~/test.git I get:

Cloning into 'test'...
user@host: Permission denied (publickey).
fatal: Could not read from remote repository.

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

also tried

  • git clone ssh://user@host/home/user/test.git
  • git clone user@host:home/user/test.git
  • git clone user@host:/home/user/test.git

with the same result

I am guessing the git credential manager isn't picking up the keys?

On the server /var/auth/log says Feb 20 02:25:36 xxxxx sshd[24674]: Connection closed by authenticating user XXXX x.x.x.x port 56433 [preauth]

  • Git version: git version 2.30.1.windows.1
  • Git Credential Manager: Git Credential Manager version 2.0.318-beta+44acfafa98 (Windows, .NET Framework 4.0.30319.42000)
  • git config -l reports credential.helper=manager-core
  • Tried both PowerShell and git bash shells, same result
  • user has read, execute permissions to the repo
Adam V. Steele
  • 559
  • 4
  • 18

2 Answers2

5

To add to @VonC's response

In git-bash things work as normal.

The normal flow of starting the ssh-agent (via eval 'ssh-agent' ), adding the key via ssh-add <path_to_key> enables git clone to work.

In PowerShell Core, or Cmd, via Windows-Terminal more work is required

the ssh-agent starts automatically (assuming you previously started the OpenSSH Authentication Agent service), adding the key works, and you can ssh after this, but git commands do NOT work, initially, but if you do

git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe

This will replace the (default) ssh that comes with git-for-windows with the Windows10 implementation.

After this it should work fine in things other than git-bash. Confirmed in Powershell-Core, Command Prompt

See also: https://gist.github.com/danieldogeanu/16c61e9b80345c5837b9e5045a701c99

Adam V. Steele
  • 559
  • 4
  • 18
1

The git credential manager is only involved for caching credentials (username/password) for HTTPS URL, not SSH.
Only the ssh-agent could be involved, for caching a possible passphrase, if the private key was defined with it.

I would try first using the full path, since ~ might not be interpreted by the remote shell, but the local (which has a different path for ~):

git clone ssh://user@host/home/user/test.git
# or
git clone user@host:/home/user/test.git

If not, in a git bash session, type:

export GIT_SSH_COMMAND='ssh -v'
git clone ...

The OP confirms in the discussion it works in a bash session:

In git bash, I started the ssh-agent,
added the key there, then it worked.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Same result on the absolute path – Adam V. Steele Feb 20 '21 at 02:33
  • 1
    @AdamV.Steele Do you have any environment variable starting with GIT_SSH? Is your private key a ppk one (putty) or an pem/openssh one (made with `ssh-keygen`)? – VonC Feb 20 '21 at 02:38
  • @AdamV.Steele I would also try `git clone user@host:/home/user/test.git` – VonC Feb 20 '21 at 02:44
  • I can `ssh` in just fine. Only git commands fail. I don't have any variables starting with `GIT_SSH`. Its an OpenSSH key – Adam V. Steele Feb 20 '21 at 02:47
  • @AdamV.Steele OK. Do you confirm `git clone user@host:/home/user/test.git` also does not work? – VonC Feb 20 '21 at 02:52
  • @AdamV.Steele Note: this is `git clone user@host:/home/user/test.git`, *not* `git clone user@host:home/user/test.git`: the `:/` is important. – VonC Feb 20 '21 at 02:53
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/228980/discussion-between-vonc-and-adam-v-steele). – VonC Feb 20 '21 at 02:54