使用 CygWin SSH 到 github 不起作用

使用 CygWin SSH 到 github 不起作用

我跟着本文在 github 上了解如何生成 ssh 密钥,但它一直要求输入密码,但我还没有设置密码!即使我设置了密码,它也会忽略它并再次要求输入密码。它声称它使用了我设置的正确密钥,但最终我被拒绝了权限。

我的密钥设置详情:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

然后,我选择默认位置~/.ssh/id_rsa并运行clip < ~/.ssh/id_rsa.pub

然后将其粘贴到 SSH 设置中的我的 github 帐户上。此外,我还将以下行添加到我的 ssh 配置中(~/.ssh/config):

Host github.com
    IdentityFile ~/.ssh/id_rsa.pub

到目前为止一切顺利。现在让我们测试一下!

'ssh [email protected] -Tv' give the following output:

$ ssh -vT [email protected]
OpenSSH_7.1p2, OpenSSL 1.0.2f  28 Jan 2016
debug1: Reading configuration data ~/.ssh/config
debug1: ~/.ssh/config line 1: Applying options for github.com
debug1: Connecting to github.com [192.30.252.128] port 22.
debug1: Connection established.
debug1: identity file ~/.ssh/id_rsa.pub type 1
debug1: key_load_public: No such file or directory
debug1: identity file ~/.ssh/id_rsa.pub-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in ~/.ssh/known_hosts:1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa.pub
debug1: Server accepts key: pkalg ssh-rsa blen 279
Enter passphrase for key '~/.ssh/id_rsa.pub':

但是没有设置密码!我点击回车,得到:

debug1: No more authentication methods to try.
Permission denied (publickey).

好的,我们再试一次,它会再次要求输入密码 :( :

$ git push -u origin master -v
Pushing to [email protected]:myUserName/myRepo.git
Enter passphrase for key '~/.ssh/id_rsa.pub':
Permission denied (publickey).
fatal: Could not read from remote repository.

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

只是为了完整性,设置密码并不能解决任何问题:

$ ssh-keygen -f id_rsa -p
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.

知道为什么它不起作用吗?:(

答案1

您的配置有误。您需要向选项提供私钥,而不是公钥IdentityFile(不带pub扩展名):

Host github.com
    IdentityFile ~/.ssh/id_rsa

相关内容