使用PuTTYgen了解SSH私钥和公钥

时间:2015-12-03 18:00:41

标签: ssh putty ssh-keys

我使用PuTTy keygen创建公钥。我将公钥复制到david.pub并发送给将密钥放在服务器(vps)上的开发人员,因此我可以克隆存储库。当我创建公钥时,我输入了密码。当我试图克隆时会发生这种情况:

$ git clone my_app:money_app.git new_money_app Cloning into 'new_money_app'... Enter passphrase for key '/c/Users/User1/.ssh/david.pub':

我输入我设置的密码,此行重复3次Enter passphrase for key '/c/Users/User1/.ssh/david.pub':

然后显示

 Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

存储库存在。这是我的配置文件的外观:

Host my_app
User git
HostName xx.xx.xxx.xx
PubkeyAuthentication yes
PreferredAuthentications publickey
IdentityFile ~/.ssh/david.pub

我如何解决这个问题,以便克隆存储库?我对GIT来说是全新的,我需要重新创建公钥吗?我被告知要创建一个公钥,我还需要一个私钥吗?

我是一名前端开发人员,所以这很令人困惑。

1 个答案:

答案 0 :(得分:3)

这不是Git问题,它只是ssh。您可以通过尝试ssh进入计算机来更轻松地调试问题。 ssh my_app会给你同样的问题。

公钥不应该有密码,应该提示你有什么问题。它一遍又一遍地问你,因为你输入了密钥没有的密码。您的私钥有密码。

在ssh中有两个键,即公共键(~/.ssh/david.pub)和私有键(~/.ssh/david)。如果没有私钥,您就无法创建公钥。私钥是你的秘密,它与你同在,它应该受密码保护,以防它被盗。公钥用于您要登录的服务器。私钥用于解锁使用公共密钥加密的内容(反之亦然)。

问题在于这一行:

IdentityFile ~/.ssh/david.pub

这应该是您的私钥~/.ssh/david