简体   繁体   English

不能克隆,可以SSH。 “权限被拒绝(公钥)。”

[英]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 .我有一个裸仓库,它位于home/user/test.git目录中的user@host目录,我试图通过git clone访问它。 I used ssh-add <pathtokey> to add my ssh key.我使用ssh-add <pathtokey>添加我的 ssh 密钥。 It asked me for the passphrase.它要求我输入密码。 I can then ssh user@host successfully.然后我可以ssh user@host成功。

However if I then try to git clone ssh://user@host/~/test.git I get:但是,如果我然后尝试git clone ssh://user@host/~/test.git我得到:

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?我猜 git 凭证管理器没有拿起钥匙?

On the server /var/auth/log says Feb 20 02:25:36 xxxxx sshd[24674]: Connection closed by authenticating user XXXX xxxx port 56433 [preauth]在服务器/var/auth/log上说Feb 20 02:25:36 xxxxx sshd[24674]: Connection closed by authenticating user XXXX xxxx port 56433 [preauth]

  • Git version: git version 2.30.1.windows.1 Git版本: 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 凭据管理器: Git Credential Manager version 2.0.318-beta+44acfafa98 (Windows, .NET Framework 4.0.30319.42000)
  • git config -l reports credential.helper=manager-core git config -l报告credential.helper=manager-core
  • Tried both PowerShell and git bash shells, same result尝试了PowerShellgit bash外壳,结果相同
  • user has read, execute permissions to the repo user已读取、执行 repo 的权限

The git credential manager is only involved for caching credentials (username/password) for HTTPS URL, not SSH. 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.如果私钥是用它定义的,那么只有 ssh-agent 可以参与缓存可能的密码短语。

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 ~ ):我会先尝试使用完整路径,因为~可能不会被远程 shell 解释,而是本地(对于~有不同的路径):

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:如果没有,请在 git bash session 中键入:

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

The OP confirms in the discussion it works in a bash session: OP 在讨论中确认它在 bash session 中工作:

In git bash, I started the ssh-agent ,在 git bash 中,我启动了ssh-agent
added the key there, then it worked.在那里添加了密钥,然后它就起作用了。

To add to @VonC's response添加到@VonC 的回复

In git-bash things work as normal.在 git-bash 中一切正常。

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.启动ssh-agent的正常流程(通过eval 'ssh-agent' ),通过ssh-add <path_to_key>密钥使git clone工作。

In PowerShell Core, or Cmd, via Windows-Terminal more work is required在 PowerShell 内核或 Cmd 中,需要通过 Windows 终端进行更多工作

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 ssh-agent自动启动(假设您之前启动了OpenSSH Authentication Agent服务),添加密钥有效,您可以在此之后使用ssh ,但git命令最初不起作用,但如果您这样做

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.这将用 Windows10 实现替换 git-for-windows 附带的(默认)ssh。

After this it should work fine in things other than git-bash.在此之后,它应该可以在 git-bash 之外的其他东西上正常工作。 Confirmed in Powershell-Core, Command Prompt在 Powershell-Core、命令提示符中确认

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM