Yus*_*205 8 git ssh github git-config
我在使用 ssh 克隆 git 存储库时遇到了一个奇怪的问题。我有 ssh 设置:
\n\nssh -T git@github.com\nHi yusufali2205! You've successfully authenticated, but GitHub does not provide shell access.\n
Run Code Online (Sandbox Code Playgroud)\n\n我正在使用正确的克隆 URL,并且可以访问我想要克隆的存储库。但出现错误:
\n\n\xe2\x9e\xa4 git clone git@github.com:<some-org>/<repo>.git\nCloning into 'project'...\nPermission denied (publickey).\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n
Run Code Online (Sandbox Code Playgroud)\n\n没有其他消息可以调试我的 ssh 设置或 git 配置有什么问题。
\n小智 6
我遇到了同样的问题,但就我而言,这是因为我使用自定义名称(例如my_key
和my_key.pub
)命名我的密钥文件,而不是ssh-keygen
使用默认名称,即:
如果您使用添加自定义命名键ssh-add
(正如许多教程所说的那样),那么该命令ssh -T git@github.com
可以完美运行,但不是该git clone
命令。
这是因为git
在使用 ssh 时仅查找具有默认名称的密钥。
我能够通过向全局添加.gitconfig
以下属性来确定这一点:
[core]
sshCommand = ssh -vvv
Run Code Online (Sandbox Code Playgroud)
当您尝试使用 ssh 克隆存储库(或其他 git 操作)时,它基本上会输出所有日志消息。
注意:我使用的是 Windows 10,该问题可能也与如何git
在 Windows 上工作有关。我还没有在 *nix 系统上测试过这个。
我发现我的中有一个条目.gitconfig
正在将 ssh 替换为 https。
[url "https"]
insteadOf = git
Run Code Online (Sandbox Code Playgroud)
我可能在使用某些工具时意外添加了此条目。所以克隆命令实际上使用的是 urlhttps@github.com:<some-org>/<repo>.git
删除上述条目后,.gitconfig
问题得到解决。