我无法使用公钥和私钥从 Jenkins 节点通过 SSH 连接到远程服务器



我正在尝试从Jenkins节点将ssh远程到远程linux机器中。我在Jenkins节点中创建了公钥和私钥,并将公钥复制到远程机器中的authorized_keys。但我无法远程进入远程机器。请检查下面的日志。

/home/us-jenkins/jenkins/workspace/engineering/dex/college-dex@tmp/durable-9222db0d/script.sh: line 8: warning: here-document at line 2 delimited by end-of-file (wanted `EOF')
+ ssh -vvv ****@208.53.147.236
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 62: Applying options for *
Pseudo-terminal will not be allocated because stdin is not a terminal.
debug1: Executing proxy command: exec /usr/bin/sss_ssh_knownhostsproxy -p 22 208.53.147.236
debug1: permanently_drop_suid: 1990977432
debug1: identity file /home/us-jenkins/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/us-jenkins/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/us-jenkins/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/us-jenkins/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/us-jenkins/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/us-jenkins/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/us-jenkins/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/us-jenkins/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
ssh_exchange_identification: Connection closed by remote host
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 255
Finished: FAILURE

如果需要任何细节,请告诉我。如有任何帮助,我们将不胜感激。

问题可以关闭。问题是我们的jenkins服务器处于受限网络中,因此SSH无法工作。我们取消了对防火墙的限制,问题得到了解决。

使用Jenkins进行SSH凭据管理后,请确保您拥有:

  • 在jenkins中将私钥注册为SSH凭据
  • 使用无密码短语的私钥,或使用SSH代理插件
  • 在管道步骤中同时使用这两个元素

示例:

stage ('Deploy') {
steps{
sshagent(credentials : ['use-the-id-from-credential-generated-by-jenkins']) {

正如评论中所指出的,Jenkins使用了一个代理命令,这意味着它的执行用户必须有一个ssh.config(类似于/etc/ssh/ssh_config(,它指示任何SSH调用通过该代理。

如果上述代理失败,这将解释错误消息。

最新更新