Maven Wagon SCP is not able to establish a connection

匿名 (未验证) 提交于 2019-12-03 02:01:02

问题:

I am trying to copy resources to another location. I am using maven wagon-ssh plugin to do this. It works fine locally, I am having issues when using Hudson/Jenkins.

My settings.xml file looks like this:

iqnouserpass

I tried this answer to skipping checking as I was getting:

Are you sure you want to continue connecting? (yes/no): The authenticity of host 'address' can't be established. RSA key fingerprint is 10:.......:bb. 

but now I am getting:

Could not apply configuration for iq to wagon org.apache.maven.wagon.providers.ssh.jsch.ScpWagon:ClassNotFoundException: Class name which was explicitly given in configuration using 'implementation' attribute: 'org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider' cannot be loaded org.codehaus.plexus.component.configurator.ComponentConfigurationException: ClassNotFoundException: Class name which was explicitly given in configuration using 'implementation' attribute: 'org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider' cannot be loaded     at org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter.getClassForImplementationHint(AbstractConfigurationConverter.java:70)     at .....  Caused by: java.lang.ClassNotFoundException: org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider     at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)     at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)     at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)     at org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter.getClassForImplementationHint(AbstractConfigurationConverter.java:61)     ... 37 more The authenticity of host 'address' can't be established. RSA key fingerprint is 10:.......:bb. Are you sure you want to continue connecting? (yes/no): The authenticity of host 'address' can't be established. 

回答1:

Are you sure you want to continue connecting? (yes/no): The authenticity of host 'address' can't be established. RSA key fingerprint is 10:.......:bb.

Yeah this happens to us as well. You seem to have fixed your problem but I thought I'd add more details for posterity.

When running under Jenkins, there is no console so no one to confirm any new ssh keys or a changes in the keys for the maven servers. To fix this, we login to our jenkins box as the jenkins user and execute the job from the workspace directory by hand from the command line. This adds the appropriate lines to the jenkins user's ssh config files.

Typing "yes" a bunch of times seems to add the key to the known-hosts file and fix the issue although you will need to restart the job to make sure.

Also, I've not tried this but you might be able to add the following to the ~jenkins/.ssh/config. See: How to Avoid Maven builds stall on ssh host authenticity problem?

StrictHostKeyChecking no 

Hope this helps someone else.



回答2:

maven apparently requires a ssh-rsa entry. You can obtain the ssh-rsa entry by issuing

ssh-keyscan -t rsa YOUR_REMOTE_HOSTNAME >> ~/.ssh/known_hosts



回答3:

The problem was that RSA keys were not exchanged.

so what I did was that, I connected both the servers from command line. So the RSA keys got stored and

Are you sure you want to continue connecting? (yes/no): The authenticity of host 'address' can't be established. RSA key fingerprint is 10:.......:bb. 

this message stopped. It works perfectly now



回答4:

This is what we use to populate known_hosts file on jenkins node:

  org.codehaus.groovy.mavengmaven-plugincheck-known-hostsinitializeexecute                 import com.jcraft.jsch.*;                 import org.apache.maven.wagon.providers.ssh.knownhost.*;                  def keyString = "" // host key - the line from known_hosts after key type (ssh-rsa)                  FileKnownHostsProvider fkhp = new FileKnownHostsProvider();                  JSch sch = new JSch();                 sch.setKnownHosts(new ByteArrayInputStream(fkhp.getContents().getBytes()));                  def host = project.properties.serverAddress // define someserveraddress.com in                    if (host != null) {                   HostKeyRepository hkr = sch.getHostKeyRepository();                   HostKey[] hk = hkr.getHostKey( host , null );                    StringWriter stringWriter = new StringWriter();                    String knownHost = host + " " + "ssh-rsa" + " " + keyString;                    if ( hk != null )                   {                      PrintWriter w = new PrintWriter( stringWriter )                     def containsKey = false;                     for ( HostKey key : hk )                     {                       def toAdd =  key.getHost() + " " + key.getType() + " " + key.getKey();                       w.println(toAdd)  ;                       containsKey = knownHost.equals(toAdd);                     }                     if (!containsKey) {                       println "Adding key for " + host + " to known_hosts"                       w.println(knownHost);                       fkhp.storeKnownHosts(stringWriter.toString() );                     } else {                       println "Key for " + host + " is already present in known_hosts"                     }                   }                 }             org.apache.maven.wagonwagon-ssh-common2.10com.jcraftjsch0.1.54

Seems to work pretty well.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!