git 中执行 ssh -v git@github.com 一直是 permission denied

2016-08-13 21:04:40 +08:00
 Qiangyuan
执行结果是下面这样的,请问有什么错?已经执行过生成 ssh key 的命令了,试了几次都没有用,请问大神是神么错?我的系统是 ubuntu16.04
OpenSSH_7.2p2 Ubuntu-4ubuntu1, OpenSSL 1.0.2g-fips 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: Connection established.
debug1: identity file /home/johnnyding/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/johnnyding/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/johnnyding/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/johnnyding/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/johnnyding/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/johnnyding/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/johnnyding/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/johnnyding/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu1
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: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: 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 /home/johnnyding/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/johnnyding/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/johnnyding/.ssh/id_dsa
debug1: Trying private key: /home/johnnyding/.ssh/id_ecdsa
debug1: Trying private key: /home/johnnyding/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
6230 次点击
所在节点    git
13 条回复
Beebird
2016-08-13 21:09:40 +08:00
首先是 key 不对,其次你这样是登录 github 主机,显然这个是被禁止的。
(假设 key 正确,报错将是” You've successfully authenticated, but GitHub does not provide shell access.”)
gkiwi
2016-08-13 21:13:44 +08:00
你看客户端其实是在遍历你的私钥,当你 ssh admin@abc.com ,应该明确告诉 ssh 用哪个秘钥;
第一种方案:

在你的~/.ssh 创建一个文件 config ,里面写入:

Host abc.com
HostName abc.com
User admin
IdentityFile ~/.ssh/id_abc_com

上面依次替换为你自己的,应该就可以了;比如我的 github ;




第二种方案:

ssh -v -i /Users/xxxx/.ssh/id_abc_com admin@abc.com
就是加上-i 参数;-v 是用来调试的,可以去掉;


至于为什么遍历时候没成功,我**猜测**可能和遍历的数量有关,不过没细看这里;
Qiangyuan
2016-08-13 21:14:22 +08:00
@Beebird 我是按照这篇文档操作的, http://blog.chinaunix.net/uid-24782829-id-3183604.html ,到第四步,执行 ssh -v git@github.com 一直是 permission denied
jerryshao
2016-08-13 21:18:28 +08:00
ssh-add ~/.ssh/id_rsa
Qiangyuan
2016-08-13 21:18:37 +08:00
@gkiwi 可是我.ssh 文件夹下没有 github 。我是按照这篇文档操作的, http://blog.chinaunix.net/uid-24782829-id-3183604.html ,到第四步,执行 ssh -v git@github.com 一直是 permission denied
Qiangyuan
2016-08-13 21:19:58 +08:00
@jerryshao 这样试了,没有用
gkiwi
2016-08-13 21:22:31 +08:00
@Qiangyuan github 是你的私钥文件,你用的是哪一个就替换成哪一个,不要看那个文档,直接去 github 上面有官方文档,那个少了 ssh-add 相关操作

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#adding-your-ssh-key-to-the-ssh-agent
Qiangyuan
2016-08-13 21:26:01 +08:00
@gkiwi 我执行这个操作后 ssh-add ~/.ssh/id_rsa ,还需要将公钥放在我的 github 账户中,再执行 ssh -v git@github.com 才可以吗,是这样的吗?
Beebird
2016-08-13 21:26:08 +08:00
ssh-add 添加的 key 太多,超过 github ssh 服务允许重试的次数。参考 @gkiwi 的方案,他是举个例子, IdentityFile 指向的是你创建 key pars 时的私钥
Qiangyuan
2016-08-13 21:43:43 +08:00
@jerryshao
@gkiwi
@Beebird
谢谢了,是少了 ssh-add ~/.ssh/id_rsa 操作,而且要把公钥添加到 github 账户中,之后执行 ssh -v git@github.com 才有效。之前参照的那篇文档描述的不对。
SourceMan
2016-08-13 22:21:56 +08:00
可以 ssh 进 github 主机?涨知识
franklinyu
2016-08-14 04:42:22 +08:00
所以說,垃圾教程害人啊……
gkiwi
2016-08-14 09:52:34 +08:00
@SourceMan ssh -v, -v 是用来调试连接的;
而 git clone 的时候不是有个 ssh 的地址么,那个就是基于 ssh 来的;



所以可以用 ssh -v git@github.com 来测试与 github.com 认证是否成功;
显然你是登陆不进 github.com 的主机的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/299114

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX