可以将 Maven Wagon 插件配置为使用 ssh/scp 的私钥吗?我尝试过的一切仍然让 maven 在到达 scp-ing 的时候向我询问密码。
4 回答
您应该能够在 settings.xml 的server元素中指定私钥的路径:
用于下载和部署的存储库由 POM的
repositories
和 元素定义。distributionManagement
但是,某些设置(例如用户名和密码)不应与 pom.xml 一起分发。此类信息应存在于构建服务器的 settings.xml 中。<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> ... <servers> <server> <id>server001</id> <username>my_login</username> <password>my_password</password> <privateKey>${user.home}/.ssh/id_dsa</privateKey> <passphrase>some_passphrase</passphrase> <filePermissions>664</filePermissions> <directoryPermissions>775</directoryPermissions> <configuration></configuration> </server> </servers> ... </settings>
- id:这是与 Maven 尝试连接的存储库/镜像的 id 元素匹配的服务器 ID(不是登录用户的 ID)。
- username , password:这些元素显示为一对,表示向此服务器进行身份验证所需的登录名和密码。
- privateKey , passphrase:与前两个元素一样,这对指定私钥的路径(
${user.home}/.ssh/id_dsa)
如果需要,默认为和密码短语。密码短语和密码元素将来可能会被外部化,但现在必须将它们设置为普通 - settings.xml 文件中的文本。- filePermissions , directoryPermissions:在部署时创建存储库文件或目录时,这些是要使用的权限。每个的合法值是一个与 *nix 文件权限相对应的三位数字,即。664 或 775。
注意:如果您使用私钥登录服务器,请确保省略该
<password>
元素。否则,密钥将被忽略。密码加密
2.1.x 和 3.0 中继中添加了一项新功能 - 服务器密码和密码短语加密。请参阅此页面上的详细信息。
特别注意“注意”:如果您使用私钥登录服务器,请确保省略该<password>
元素。否则,密钥将被忽略。所以最终的配置会接近:
<settings>
...
<servers>
<server>
<id>ssh-repository</id>
<username>your username in the remote system</username>
<privateKey>/path/to/your/private/key</privateKey>
<passphrase>sUp3rStr0ngP4s5wOrD</passphrase><!-- if required -->
<configuration>
...
</configuration>
</server>
</servers>
...
</settings>
今天我想与maven-site-plugin (3.9.1) 一起做同样的事情,但也遇到了一些障碍(具体来说,wagon-ssh插件坚持要求我提供我的 Kerberos 用户名和密码)。wagon-ssh- 3.4.3最终对我有用:
<!-- add scp support for mvn site:deploy -->
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>3.4.3</version>
</dependency>
在settings.xml 中:
<server>
<id>ssh-repository</id>
<username>pridkdev</username>
<privateKey>${user.home}/.ssh/pridkdev.ppk</privateKey>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration>
<interactive>false</interactive>
<strictHostKeyChecking>no</strictHostKeyChecking>
<preferredAuthentications>publickey</preferredAuthentications>
</configuration>
</server>
我想关键是<configuration>
块,尤其是<preferredAuthentications>
设置。
我知道这是一个旧线程,但看起来 Wagon 插件正在读取 settings.xml(例如用户名)但没有使用所有设置。我无法让它在 scp 期间停止询问 Kerberos 用户名/密码。(看起来可能在 2016 年末对插件进行了更改,这会影响到这一点。)只需添加此答案,以防它对其他人有所帮助。
对我来说,解决方案更简单:完全跳过使用“settings.xml”并简单地为协议指定“scpexe”而不是“scp”(如在 pom.xml 的 distributionManagement 部分下)。然后,这将使用您机器的默认 SSH 配置(~/.ssh 下的 unix 设置)。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>upload-to-server</id>
<phase>deploy</phase>
<goals><goal>upload-single</goal></goals>
<configuration>
<fromFile>file-to-upload</fromfile>
<url>scpexe://username@serverName/dirname-to-copy-to
<toFile>file-to-upload</toFile>
</configuration>
</execution>
</executions>
</plugin>
我在这里找到了必要的信息: http ://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ssh-external.html