I know this is a very old topic, however I thought I'd add to it in case the original author will still get updates and for anyone else running into issues who comes across this thread.
For myself, the issue was not having the public key (that was generated on the server you're trying to connect to), in the authorized_keys file. I'll explain a bit further to provide context. Our Jenkins ID didn't have access to publish artifacts out to the folder we needed to push them to after doing the build. In order to get around it, we were trying to setup a pipeline script and use sshagent to ssh back into the same server Jenkins is running on but with a different user ID. In order to accomplish this, I logged onto the Jenkins server and navigated to the .ssh directory for the user that had the proper folder access. From that location, I generated a new keypair, created the "authorized_keys" file (directly within the .ssh folder) and then added the newly generated public key into it. That was the piece we were missing that was preventing us from properly connecting. After that, we created the credential in Jenkins with the private key. From there, we were able to use that user in our ssh command and it connected and executed commands properly. On Thursday, June 2, 2016 at 9:10:16 AM UTC-5, Sverre Moe wrote: > > I need to transfer some files to a server. > Have followed the suggestion mention in > https://issues.jenkins-ci.org/browse/JENKINS-27963 > Tried sshagent with both scp and rsync. Neither works. > > I have created a Credential for this server in Jenkins. > > Using rsync > sshagent(['repository']) { > sh "rsync -av *.rpm > r...@server.company.com:/srv/www/htdocs/staging_rpms/" > } > > [ssh-agent] Using credentials build (repohost) > [ssh-agent] Looking for ssh-agent implementation... > [ssh-agent] Java/JNR ssh-agent > [ssh-agent] Started. > [Pipeline] { > [Pipeline] sh > [master] Running shell script > + rsync -av *.rpm r...@server.company.com:/srv/www/htdocs/staging_rpms > Host key verification failed. > rsync: connection unexpectedly closed (0 bytes received so far) [sender] > rsync error: error in rsync protocol data stream (code 12) at io.c(641) > [sender=3.0.4] > > > Using scp > sshagent(['repository']) { > sh "scp *.rpm r...@server.company.com:/srv/www/htdocs/staging_rpms/" > } > > [ssh-agent] Using credentials build (repohost) > [ssh-agent] Looking for ssh-agent implementation... > [ssh-agent] Java/JNR ssh-agent > [ssh-agent] Started. > [Pipeline] { > [Pipeline] sh > [master] Running shell script > + scp *.rpm r...@server.company.com:/srv/www/htdocs/staging_rpms/ > Host key verification failed. > lost connection > > Problem because of this: > The authenticity of host 'server.company.com (192.24.17.73)' can't be > established. > ECDSA key fingerprint is 00:00:00:00:00:00:00:bc:cc:51:3f:39:f8:06:df:18 > [MD5]. > Are you sure you want to continue connecting (yes/no)? yes > Warning: Permanently added 'server.company.com' (ECDSA) to the list of > known hosts. > > Fixing this first "manually" and continued. > > Using rsync > [ssh-agent] Using credentials build (repohost) > [ssh-agent] Looking for ssh-agent implementation... > [ssh-agent] Java/JNR ssh-agent > [ssh-agent] Started. > [Pipeline] { > [Pipeline] sh > [master] Running shell script > + rsync -av *.rpm r...@server.company.com:/srv/www/htdocs/staging_rpms/ > Permission denied (publickey,keyboard-interactive). > rsync: connection unexpectedly closed (0 bytes received so far) [sender] > rsync error: error in rsync protocol data stream (code 12) at io.c(641) > [sender=3.0.4] > > Using scp > [ssh-agent] Using credentials build (repohost) > [ssh-agent] Looking for ssh-agent implementation... > [ssh-agent] Java/JNR ssh-agent > [ssh-agent] Started. > [Pipeline] { > [Pipeline] sh > [master] Running shell script > + scp *.rpm r...@server.company.com:/srv/www/htdocs/staging_rpms/ > Permission denied (publickey,keyboard-interactive). > lost connection > -- 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 jenkinsci-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/46b0e807-e7f0-4593-a63c-7f9802dbde43%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.