Search code examples
windowsgitsshgit-credential-manager

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


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

Solution

  • 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.