命令行Git无法识别使用GitHub for Windows生成的密钥
问题描述:
我已经为Windows设置了GitHub并使用它来创建与我的帐户相关联的SSH密钥。我可以在GitHub上的Windows GUI执行git的操作,但是当我尝试运行命令在命令提示符像git clone [email protected]:whatever.git
我得到一个错误这样的:命令行Git无法识别使用GitHub for Windows生成的密钥
C:\Users\Nat\Documents\GitHub>git clone [email protected]:natdempk/whatever.git
Cloning into 'whatever'...
Permission denied (publickey).
fatal: Could not read from remote repository.
为什么会出现这种情况时,一切从GitHub的工作对于Windows GUI?
答
当GitHub for Windows创建密钥时,它们被命名为github_rsa
和github_rsa.pub
。 git
预计密钥默认命名为id_rsa
和id_rsa.pub
,所以它不会从GitHub for Windows中找到密钥,并会给你Permission denied (publickey)
。为了解决这个问题,你应该创建github.com
为C:\users\<username>\.ssh\config
一个SSH的配置文件看起来像下面这样:
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_rsa
此通知git
进行连接到github.com
操作时,使用生成的GitHub的Windows键。