【问题标题】:Maven Wagon SCP is not able to establish a connectionMaven Wagon SCP 无法建立连接
【发布时间】:2012-01-09 12:25:12
【问题描述】:

我正在尝试将资源复制到另一个位置。我正在使用 maven wagon-ssh 插件来执行此操作。它在本地运行良好,我在使用 Hudson/Jenkins 时遇到问题。

我的settings.xml 文件如下所示:

<servers>
    <server>
        <id>iq</id>
        <configuration>
            <knownHostsProvider implementation="org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider">
                <hostKeyChecking>no</hostKeyChecking>
            </knownHostsProvider>
        </configuration>
        <username>user</username>
        <password>pass</password>
    </server>
</servers>

我尝试了this answer to skipping checking,因为我得到了:

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.

但现在我得到了:

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.

【问题讨论】:

  • 请考虑从我的回答切换到@CharlesHu's。
  • @Gray 谢谢并完成

标签: maven ssh wagon


【解决方案1】:

maven 显然需要 jenkins 用户在 known_hosts 文件中的 ssh-rsa 条目。您可以通过发出以下命令将 ssh-rsa 条目添加到文件中:

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

[[ 从另一个答案中添加以使这个答案成为确定的。 ]]

相反,您可以将以下内容添加到~jenkins/.ssh/config。见:How to Avoid Maven builds stall on ssh host authenticity problem?

StrictHostKeyChecking no

【讨论】:

  • 使用 Bamboo,我发现构建代理不一定使用服务器的 ssh 配置文件。对于这种情况(根据我的回答)我发现在目标服务器的settings.xml 文件中禁用StrictHostKeyChecking 有效。
【解决方案2】:

问题是没有交换 RSA 密钥。

所以我所做的是,我从命令行连接了两个服务器。所以 RSA 密钥被存储和

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.

此消息已停止。现在完美运行

【讨论】:

  • 如果对您有用,您可以接受自己的答案是正确的。
  • 谢谢@ArtB。我已经忘记了
  • @Gray 我在 jenkins 上执行它,所以按 Enter 不会有帮助:)
  • 看我的 cmets 到一个答案。
【解决方案3】:

Wagon-ssh 将为您完成这项工作。无需手动或脚本复制指纹。

仅在 settings.xml 文件中禁用 strict 主机密钥检查。

<servers>
    <server>
        <id>iq</id>
        <configuration>

            <StrictHostKeyChecking>no</StrictHostKeyChecking>

        </configuration>
        <username>user</username>
        <password>pass</password>
    </server>
</servers>

主机指纹被自动接受并存储在known_hosts 文件中。其余的身份验证过程照常进行。

这在 Bamboo 构建服务器上成功运行,构建代理具有自己的本地 ssh 配置文件。

【讨论】:

    【解决方案4】:

    这是我们用来在 jenkins 节点上填充 known_hosts 文件的内容:

      <plugin>
        <groupId>org.codehaus.groovy.maven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <executions>
          <execution>
              <id>check-known-hosts</id>
              <phase>initialize</phase>
              <goals>
                <goal>execute</goal>
              </goals>
              <configuration>
                <source>
                    import com.jcraft.jsch.*;
                    import org.apache.maven.wagon.providers.ssh.knownhost.*;
    
                    def keyString = "<REPLACE_WITH_HOST_KEY>" // 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 <serverAddress>someserveraddress.com</serverAddress> in <properties> 
    
                    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"
                        }
                      }
                    }
                </source>
              </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ssh-common</artifactId>
            <version>2.10</version>
          </dependency>
          <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.54</version>
          </dependency>
        </dependencies>
      </plugin>
    

    似乎工作得很好。

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 2011-02-13
      • 1970-01-01
      • 2019-12-26
      • 2015-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      相关资源
      最近更新 更多