sshAgent connection error through Pipeline with Private key

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

sshAgent connection error through Pipeline with Private key

sabharwal81
Hello everyone,

I am stuck with one odd problem where i am trying to run remote command on linux server from my slave machine (windows server) as part of Pipeline script. As SSH connections are only supported using Private/Public Keys, i did follow steps mentioned in blog https://medium.com/@weblab_tech/how-to-publish-artifacts-in-jenkins-f021b17fde71 to generate keys to be later used for calls. Below are things i have done so far:
- Connected to slave server and created key using ssh-keygen.
- Created new credential using key/passphrase in Jenkins (id as server_ssh_key).
- Copied over the public key under /authorized_keys (id_rsa.pub) on the remote server.
- Connected from Slave server to the remote linux server through console to allow entry to "known host" file on the slave server.
- Updated Pipeline script to use below code to allow use of newly created credentials.
pipeline {
    options {
        timestamps()
    }
    agent {label 'att_server_slave'}
    stages {
        stage('Builds') {
steps {
script{
stage ('Starting build_rhel56_x64_1')  
{
  sshagent(credentials: ['server_ssh_key']) {

ssh 'root@192.168.2.111 ls'
}
}
}
}
        }
    }
}

when i am trying to run this pipeline script, i am getting below error:

00:13:26 [ssh-agent] Using credentials root
00:13:26 [ssh-agent] Looking for ssh-agent implementation...
00:13:27 [ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
00:13:27 $ ssh-agent
00:13:27 SSH_AUTH_SOCK=/tmp/ssh-OzJHVK5660/agent.5660
00:13:27 SSH_AGENT_PID=6056
00:13:27 $ ssh-add C:\EngineJenkins\workspace\pipeline_test@tmp\private_key_3271471486698300052.key
00:13:28       3 [main] ssh-add 2176 tty_list::allocate_tty: No tty allocated

Can someone please help in understanding what wrong i am doing? Or what specific check/step i am missing?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/73636eda-0809-441d-8b99-65f97b6236e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sshAgent connection error through Pipeline with Private key

Jimmy Bway
Hi,

Wanted to know if somehow you found a solution ?

If yes please share.

Regards

Le mardi 5 septembre 2017 19:38:07 UTC-4, sabharwal81 a écrit :
Hello everyone,

I am stuck with one odd problem where i am trying to run remote command on linux server from my slave machine (windows server) as part of Pipeline script. As SSH connections are only supported using Private/Public Keys, i did follow steps mentioned in blog <a href="https://medium.com/@weblab_tech/how-to-publish-artifacts-in-jenkins-f021b17fde71" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2F%40weblab_tech%2Fhow-to-publish-artifacts-in-jenkins-f021b17fde71\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFe5ByziC5-tE7y_7pSWHB2Rzdw-w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2F%40weblab_tech%2Fhow-to-publish-artifacts-in-jenkins-f021b17fde71\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFe5ByziC5-tE7y_7pSWHB2Rzdw-w&#39;;return true;">https://medium.com/@weblab_tech/how-to-publish-artifacts-in-jenkins-f021b17fde71 to generate keys to be later used for calls. Below are things i have done so far:
- Connected to slave server and created key using ssh-keygen.
- Created new credential using key/passphrase in Jenkins (id as server_ssh_key).
- Copied over the public key under /authorized_keys (id_rsa.pub) on the remote server.
- Connected from Slave server to the remote linux server through console to allow entry to "known host" file on the slave server.
- Updated Pipeline script to use below code to allow use of newly created credentials.
pipeline {
    options {
        timestamps()
    }
    agent {label 'att_server_slave'}
    stages {
        stage('Builds') {
steps {
script{
stage ('Starting build_rhel56_x64_1')  
{
  sshagent(credentials: ['server_ssh_key']) {

ssh '<a href="javascript:" target="_blank" gdf-obfuscated-mailto="-GmBshI6AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ro...@192.168.2.111 ls'
}
}
}
}
        }
    }
}

when i am trying to run this pipeline script, i am getting below error:

00:13:26 [ssh-agent] Using credentials root
00:13:26 [ssh-agent] Looking for ssh-agent implementation...
00:13:27 [ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
00:13:27 $ ssh-agent
00:13:27 SSH_AUTH_SOCK=/tmp/ssh-OzJHVK5660/agent.5660
00:13:27 SSH_AGENT_PID=6056
00:13:27 $ ssh-add C:\EngineJenkins\workspace\pipeline_test@tmp\private_key_3271471486698300052.key
00:13:28       3 [main] ssh-add 2176 tty_list::allocate_tty: No tty allocated

Can someone please help in understanding what wrong i am doing? Or what specific check/step i am missing?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2d13fb7e-44e2-4976-8c27-d437b1e15cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.