2

使用站点部署时如何摆脱此提示?“你确定要继续连接吗?”

我知道这个问题已被多次询问(链接链接),但推荐的解决方案对我不起作用,我将解释原因。

哦,我在这里发布了几乎完全相同的问题

解决方案是:

# Run this manually:
ssh -o UserKnownHostsFile=foo javadoc.foo.com

# Take that file and put it in your private DAV share, and then
ssh -o UserKnownHostsFile=/private/<account>/known_hosts javadoc.foo.com

它在 99% 的时间里都运行良好,但是使用这个解决方案,我们每隔一段时间就会在日志中一遍又一遍地看到以下文本:

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
3d:69:41:8a:ec:d1:4c:d9:75:ef:7d:71:b7:7d:61:d0.
Please contact your system administrator.
Add correct host key in known_hosts to get rid of this message.
Do you want to delete the old key and insert the new key? (yes/no)

所以,回到我的问题:简而言之,问题是这样的:当我运行 mvn site-deploy 时,它在 Jenkins 中陷入了无限循环:

The authenticity of host 'javadoc.foo.com' can't be established.
RSA key fingerprint is 3d:69:41:8a:ec:d1:4c:d9:75:ef:7d:71:b7:7d:61:d0.
Are you sure you want to continue connecting? (yes/no)
The authenticity of host 'javadoc.foo.com' can't be established.
RSA key fingerprint is 3d:69:41:8a:ec:d1:4c:d9:75:ef:7d:71:b7:7d:61:d0.
Are you sure you want to continue connecting? (yes/no)

发生这种情况的机器是 CloudBees 机器,所以它不是我们拥有的机器。换句话说,每次我们进行构建时,都会为我们提供一台全新的机器。

我们的 settings.xml 有类似的东西:

<server>
    <id>javadoc.foo.com</id>
    <username>username</username>
    <password>password</password>
</server>

如果它是我们拥有和控制的机器,我们可以在那里手动 ssh 并运行 ssh 命令一次,这样就可以解决这个问题,但就像我说的那样,这些机器是动态配置给我们的。

由于我们使用的是 maven 3 而不是 maven 2,因此我们无法将以下内容添加到 settings.xml 的服务器部分:

<configuration>
    <knownHostsProvider implementation="org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider">
        <hostKeyChecking>no</hostKeyChecking>
    </knownHostsProvider>
</configuration>

有没有办法:

  1. 以编程方式回答是(这不是自由风格的 Jenkins 工作;这是 Maven 项目。)
  2. 站点部署的替代方案(pom.xml 中的蚂蚁代码?)
  3. 如果这个问题没有得到回答,则站点部署失败,这样 Jenkins 构建就不会用一遍又一遍地重复这个问题来填充磁盘空间。
  4. 告诉 site-deploy 插件将 stricthostkeychecking 设置为“no”

我想避免任何可能调整 ssh 设置的预构建步骤;我更愿意调整 settings.xml、pom.xml 或 maven 选项。

尽管如此,我愿意接受任何建议。

4

5 回答 5

4

您可以使用以下settings.xml配置使其工作:

<server>
  <id>site</id>
  <username>_your_login_user_</username>
  <privateKey>_path_to_key_identify_file</privateKey>
  <configuration>
    <strictHostKeyChecking>no</strictHostKeyChecking>
    <preferredAuthentications>publickey,password</preferredAuthentications>
    <interactive>false</interactive>
  </configuration>
</server>

连同以下pom.xml

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-site-plugin</artifactId>
   <version>3.6</version>
     <dependencies>
       <dependency><!-- add support for ssh/scp -->
           <groupId>org.apache.maven.wagon</groupId>
           <artifactId>wagon-ssh</artifactId>
           <version>2.12</version>
       </dependency>
     </dependencies>
 </plugin>

一个问题https://issues.apache.org/jira/browse/WAGON-467已经解决了 wagon-ssh 插件的strictHostKeyChecking参数,并在最近的版本中得到了解决。

于 2017-03-27T14:17:27.570 回答
1

添加一个 shell 预构建步骤来创建 ~/.ssh/config 内容:

StrictHostKeyChecking no

于 2013-08-22T09:15:57.623 回答
1
echo yes | mvn site:deploy 

尽管尝试了许多其他路线,但完全为我解决了这个问题。

于 2021-02-17T13:34:39.513 回答
0

我找不到解决这个问题的方法。使用这个不起作用:org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider,这似乎是一个已知问题。

但是假设您在某种 unix 机器上,您可以这样做作为一种解决方法,如果您不想更改 ssh 配置,则在提示时发送“是”:

echo yes | mvn site:deploy 
于 2016-03-04T10:19:34.440 回答
0

对于有人不会使用的情况,StrictHostKeyChecking no如果有人在 Windows 上遇到这个问题,我还有另一个解决方案:

Normaly 你known_hosts可以在下面找到

C:\Users\<你的用户名>\.ssh\known_hosts

对于 Jenkins 的 Windows 服务安装,您应该将您的复制known_hosts到:

C:\Windows\System32\config\systemprofile\.ssh\

或者对于 Jenkins 64Bit 版本:

C:\Windows\SysWOW64\config\systemprofile\.ssh\

对于 Unix/Linux 系统,使用模拟路径 - 将 known_hosts(或仅部分)从您的帐户复制到 Jenkins 用户。

于 2019-08-09T21:07:38.353 回答