【问题标题】:Permission denied (publickey) when trying to ssh to GIT from a slave node尝试从从节点 ssh 到 GIT 时权限被拒绝(公钥)
【发布时间】:2017-11-22 02:45:03
【问题描述】:

所以我正在尝试为 Jenkins 设置一个 ssh 密钥。出于某种原因,我得到了:

Permission denied (publickey). 

完整的堆栈跟踪是:

[jenkins@ip-xx-xx-xx-xxx .ssh]$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[jenkins@ip-xx-xx-x-xxx .ssh]$ ssh -vT ddennis@git.xxxxxx.com
OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to git.viasat.com [xx.xx.xxx.xx] port 22.
debug1: Connection established.
debug1: identity file /home/jenkins/.ssh/id_rsa type 1
debug1: identity file /home/jenkins/.ssh/id_rsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_dsa type -1
debug1: identity file /home/jenkins/.ssh/id_dsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_ecdsa type -1
debug1: identity file /home/jenkins/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_ed25519 type -1
debug1: identity file /home/jenkins/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: kex: ecdh-sha2-nistp256 need=20 dh_need=20
debug1: kex: ecdh-sha2-nistp256 need=20 dh_need=20
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA aa:f3:39:39:58:2b:61:ad:e8:d3:7a:f2:d2:e9:dd:7a
debug1: Host 'git.xxxxxx.com' is known and matches the ECDSA host key.
debug1: Found key in /home/jenkins/.ssh/known_hosts:3
debug1: ssh_ecdsa_verify: signature correct
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: /home/jenkins/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/jenkins/.ssh/id_dsa
debug1: Trying private key: /home/jenkins/.ssh/id_ecdsa
debug1: Trying private key: /home/jenkins/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

我也在 git 中将 ssh 密钥设置为我的用户。
我跑了:

[jenkins@ip-xx-xx-xx-xxx .ssh]$ ssh-add -l
4096 9e:93:0c:12:4c:74:a6:e4:f0:eb:a1:28:d4:44:46:71 /home/jenkins/.ssh/id_rsa (RSA)

在我的从节点上,它与加载到 git 中的节点匹配。
我还将该密钥的副本复制到了我的授权密钥文件中。
玩了一段时间,任何建议都是有帮助的。

【问题讨论】:

    标签: amazon-web-services jenkins ssh amazon-ec2


    【解决方案1】:

    首先尝试生成不带密码的 ssh 密钥:这样您就不必担心 ssh-add。

    ssh-keygen -t rsa -C "key for xxx access" -q -P ""
    

    (不需要腻子as seen in "AWS Troubleshooting Instances Connecting"
    (不需要for the console, which creates ppk/pem ssh keys

    确保permissions are correct, both on the client and server side, regarding ssh

    确保您已正确复制服务器中的公钥:

    ~/ddennis/.ssh/authorized_keys 
    

    (作为一条连续线)


    之后,如果ssh -Tv可以工作,而Jenkins本身不工作,一般是因为Jenkins没有用同一个账号运行,也没有寻找同一套ssh密钥。

    【讨论】:

    • 所以这似乎解决了它。我一定是一个许可的东西。但出于某种原因,在 Jenkins 上,我仍然收到返回状态代码 128:stdout:stderr:Permission denied(publickey)。致命:无法从远程存储库中读取。但它正在提取代码并成功构建。如果您对此有任何见解。对我来说似乎很奇怪。
    • @DavidDennis if ssh -Tv 确实有效,但 Jenkins 本身不起作用,一般是因为 Jenkins 没有使用相同的帐户运行,并且没有寻找相同的 ssh 密钥集。
    • 这就是我正在寻找的答案。谢谢。
    • @DavidDennis 太棒了!我已将评论包含在答案中以获得更多可见性。
    猜你喜欢
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 2014-11-08
    • 2019-03-11
    相关资源
    最近更新 更多