V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
Qiangyuan
V2EX  ›  git

git 中执行 ssh -v [email protected] 一直是 permission denied

  •  
  •   Qiangyuan · 2016-08-13 21:04:40 +08:00 · 6288 次点击
    这是一个创建于 3006 天前的主题,其中的信息可能已经有所发展或是发生改变。
    执行结果是下面这样的,请问有什么错?已经执行过生成 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: [email protected]
    debug1: kex: host key algorithm: ssh-rsa
    debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
    debug1: kex: client->server cipher: [email protected] 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).
    13 条回复    2016-08-14 09:52:34 +08:00
    Beebird
        1
    Beebird  
       2016-08-13 21:09:40 +08:00
    首先是 key 不对,其次你这样是登录 github 主机,显然这个是被禁止的。
    (假设 key 正确,报错将是” You've successfully authenticated, but GitHub does not provide shell access.”)
    gkiwi
        2
    gkiwi  
       2016-08-13 21:13:44 +08:00
    你看客户端其实是在遍历你的私钥,当你 ssh [email protected] ,应该明确告诉 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 [email protected]
    就是加上-i 参数;-v 是用来调试的,可以去掉;


    至于为什么遍历时候没成功,我**猜测**可能和遍历的数量有关,不过没细看这里;
    Qiangyuan
        3
    Qiangyuan  
    OP
       2016-08-13 21:14:22 +08:00
    @Beebird 我是按照这篇文档操作的, http://blog.chinaunix.net/uid-24782829-id-3183604.html ,到第四步,执行 ssh -v [email protected] 一直是 permission denied
    jerryshao
        4
    jerryshao  
       2016-08-13 21:18:28 +08:00
    ssh-add ~/.ssh/id_rsa
    Qiangyuan
        5
    Qiangyuan  
    OP
       2016-08-13 21:18:37 +08:00
    @gkiwi 可是我.ssh 文件夹下没有 github 。我是按照这篇文档操作的, http://blog.chinaunix.net/uid-24782829-id-3183604.html ,到第四步,执行 ssh -v [email protected] 一直是 permission denied
    Qiangyuan
        6
    Qiangyuan  
    OP
       2016-08-13 21:19:58 +08:00
    @jerryshao 这样试了,没有用
    gkiwi
        7
    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
        8
    Qiangyuan  
    OP
       2016-08-13 21:26:01 +08:00
    @gkiwi 我执行这个操作后 ssh-add ~/.ssh/id_rsa ,还需要将公钥放在我的 github 账户中,再执行 ssh -v [email protected] 才可以吗,是这样的吗?
    Beebird
        9
    Beebird  
       2016-08-13 21:26:08 +08:00
    ssh-add 添加的 key 太多,超过 github ssh 服务允许重试的次数。参考 @gkiwi 的方案,他是举个例子, IdentityFile 指向的是你创建 key pars 时的私钥
    Qiangyuan
        10
    Qiangyuan  
    OP
       2016-08-13 21:43:43 +08:00
    @jerryshao
    @gkiwi
    @Beebird
    谢谢了,是少了 ssh-add ~/.ssh/id_rsa 操作,而且要把公钥添加到 github 账户中,之后执行 ssh -v [email protected] 才有效。之前参照的那篇文档描述的不对。
    SourceMan
        11
    SourceMan  
       2016-08-13 22:21:56 +08:00 via iPhone
    可以 ssh 进 github 主机?涨知识
    franklinyu
        12
    franklinyu  
       2016-08-14 04:42:22 +08:00
    所以說,垃圾教程害人啊……
    gkiwi
        13
    gkiwi  
       2016-08-14 09:52:34 +08:00
    @SourceMan ssh -v, -v 是用来调试连接的;
    而 git clone 的时候不是有个 ssh 的地址么,那个就是基于 ssh 来的;



    所以可以用 ssh -v [email protected] 来测试与 github.com 认证是否成功;
    显然你是登陆不进 github.com 的主机的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1005 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 21:04 · PVG 05:04 · LAX 13:04 · JFK 16:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.