简体   繁体   English

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

[英]I can't able to SSH into remote server from Jenkins node using public and private Key

I am trying to remote ssh into remote linux machine from Jenkins node.我正在尝试从 Jenkins 节点远程 ssh 进入远程 linux 机器。 I created public and private key in Jenkins node and copied the public key to authorized_keys in remote machine.我在 Jenkins 节点中创建了公钥和私钥,并将公钥复制到远程机器中的 authorized_keys。 But I can't able to remote into remote machine.但我无法远程进入远程机器。 Please check the logs below.请检查下面的日志。

/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

Please let me know if any details are needed.如果需要任何详细信息,请告诉我。 Any help will be highly appreciated.任何帮助将不胜感激。

The issue can be closed.该问题可以关闭。 The issue is our jenkins server is in restricted network hence SSH won't work.问题是我们的 jenkins 服务器位于受限网络中,因此 SSH 无法正常工作。 We removed the restriction on firewall and the issue was fixed.我们取消了对防火墙的限制,问题得到解决。

Following SSH Credentials Management with Jenkins , make sure you have:遵循Jenkins 的 SSH 凭证管理,确保您拥有:

  • registered the private key as an SSH credentials in jenkins在 jenkins 中将私钥注册为 SSH 凭据
  • use a passphrase-less private key, or use the SSH Agent plugin使用无密码的私钥,或使用SSH 代理插件
  • use both of those elements in your pipeline step在您的管道步骤中使用这两个元素

Example :示例

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

As noted in the comments , Jenkins uses a proxy command which means its execution user must have a ssh.config (like /etc/ssh/ssh_config ) which instructs any SSH call to go through that proxy.评论中所述Jenkins 使用代理命令,这意味着其执行用户必须有一个ssh.config (如/etc/ssh/ssh_config ),它指示任何 SSH 调用通过该代理。

If said proxy fails, that would explain the error message.如果所述代理失败,那将解释错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM