如何使用Maven使用私钥部署SCP

时间:2014-12-18 03:36:39

标签: xml maven deployment scp

在Windows上使用Maven,使用私钥在SCP上传输。 这似乎是一个非常简单和有记录的过程。但它对我不起作用。

在settings.xml中

<server>
  <id>myserver</id>
  <username>me</username>
  <privateKey>C:/data/home/.ssh/id_rsa</privateKey>
</server>

在pom.xml中

<distributionManagement>
  <repository>
    <id>myserver</id>
    <url>scp://myserver.domain.com/~me/deploy</url>
  </repository>
</distributionManagement>
<build>
  <extensions>
    <!-- Enabling the use of FTP -->
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-ssh</artifactId>
       <version>2.8</version>
    </extension>
  </extensions>
</build>

期望是,它不应该要求我输入密码才能登录。另请注意,我不想使用外部命令使其在不同平台上统一工作。但是......

--- maven-deploy-plugin:2.7:deploy (default-deploy) @ sparksample ---
Downloading: scp://myserver.domain.com/~me/deploy/com/domain/myproject/1.0-SNAPSHOT/maven-metadata.xml 
The authenticity of host 'myserver.domain.com' can't be established.
RSA key fingerprint is 01:01:01:01:01:01:01:01:01:01:01:01:01:01:01:ff.
Are you sure you want to continue connecting? (yes/no): yes
: Password for me@myserver.domain.com: 

不仅要求我输入密码,它还强迫我每次都接受主机密钥。 但它确实拾取了settings.xml文件,因为它使用正确的用户名进行连接。

那么如何避免它向我询问密码,并使用提供的私钥?请注意,我能够使用完全相同的私钥文件成功执行ant scp任务。

1 个答案:

答案 0 :(得分:1)

应正确设置读/写权限

# Current directory should not be writable by others (and preferably not by group either):
chmod o-w ~

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa

# Only in case id_rsa.pub exists (644 also ok):
chmod 640 ~/.ssh/id_rsa.pub
chmod 640 ~/.ssh/authorized_keys

应正确设置所有权

设置为当前用户和默认组。通过省略该组 冒号后,确保将组重置为默认值 对于那个用户。

chown ${USER}: ~
chown -R ${USER}: ~/.ssh