如何通过使用Maven的私钥在SCP上部署 [英] How to deploy over SCP with private key using Maven

查看:349
本文介绍了如何通过使用Maven的私钥在SCP上部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows上使用Maven,使用私钥在SCP上传输。
这似乎是一个非常简单和记录的过程。但是这对我来说并不奏效。



在settings.xml中

 <服务器> 
< 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>
<! - 启用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 --- 
下载:scp://myserver.domain.com/~me/deploy/com/domain/myproject/1.0-SNAPSHOT/maven-metadata.xml
主机'myserver.domain.com的真实性不能建立
RSA钥匙指纹为01:01:01:01:01:01:01:01:01:01:01:01:01:01:01:ff
您确定要继续连接吗? (是/否):是
:密码为me@myserver.domain.com:

不仅要求我密码,还会迫使我每次接受主机。
然而,它接收到settings.xml文件,因为它正在使用正确的用户名来连接。



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

解决方案

写权限应正确设置



 #当前目录不应由其他人写入(最好不要按组别):
chmod ow〜

chmod 700〜/ .ssh
chmod 600〜/ .ssh / id_rsa

#只有在这种情况下id_rsa.pub存在(644也可以):
chmod 640〜/ .ssh / id_rsa.pub
chmod 640〜/ .ssh / authorized_keys



所有权应正确设置



设置为当前用户和默认组。通过在冒号后省略组
,确保该组被重置为该用户的默认

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


Using Maven on windows, transfer over SCP, using a private key. It seems to be a very simple and documented process. But it didn't work for me.

In the settings.xml

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

In the 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>

The expectation is, it should not come to ask me for a password to login. Also note that I do not want to use an external command to make it work uniformly across platforms. However ...

--- 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: 

Not only asks it me for a password, it also forces me every time to accept the hostkey. It did however pickup the settings.xml file, as it is using the correct username to connect.

So how do I avoid it to ask me the password, and use the provided private key? Note that I was able to do this successfully with an ant scp task, using the exact same private key file.

解决方案

Read/Write Privileges should be set correctly

# 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

Ownership should be set correctly

Set to current user and default group. By omitting the group after the colon, you make sure the group is reset to the default for that user.

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

这篇关于如何通过使用Maven的私钥在SCP上部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆