Can't clone, can SSH. "Permission denied (publickey)."

Viewed 1060

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
2 Answers

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

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.

Related