Can the Maven Wagon plugin use the private key for scp?

Can I configure the Maven Wagon plugin to use the private key for ssh / scp? Everything I tried leaves maven anyway to ask me for a password when it reaches the scp-ing point.

+8
maven-2 ssh ssh-keys
source share
3 answers

You must specify the path to the private key in the server element in your .xml settings:

The repositories for download and deployment are determined by the repositories and distributionManagement elements of the POM. However, some settings such as username and password should not be distributed with pom.xml. This type of information must exist on the build server in 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 : this is the server (not user login) identifier that matches the id element of the repository / mirror that Maven is trying to connect to.
  • username , password . These elements are displayed as a pair denoting the username and password required for authentication on this server.
  • PrivateKey , passphrase . Like the previous two elements, this pair indicates the path to the private key (the default is ${user.home}/.ssh/id_dsa) and passphrase, if required. the elements of the passphrase and password may be externalized in the future, but for now they must be set in the text file settings.xml.
  • filePermissions , directoryPermissions . When a repository file or directory is created during deployment, these are permissions to use. The legal values โ€‹โ€‹of each of them is a three-digit number corresponding to the * nix permission file, i.e. 664 or 775.

Note. If you are using the private key to log in to the server, make sure you omit the <password> element. Otherwise, the key will be ignored.

Password encryption

A new feature is the server password, and password phrase encryption has been added to 2.1.x and 3.0 trunks. See details on this page .

Pay particular attention to the "note": if you use the private key to log into the server, make sure that you omit the <password> element. Otherwise, the key will be ignored. Thus, the final configuration will be close to:

 <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> 
+14
source share
+1
source share

I know this is an old thread, but it looks like the Wagon plugin reads settings.xml (e.g. username) but doesn't use all the settings. I could not get it to stop asking for Kerberos username / password during scp. (It looks like plugins may be changed at the end of 2016 that affect this.) Just add this answer if it helps someone else.

The solution was even simpler for me: skip completely using 'settings.xml' and just specify โ€œscpexeโ€ instead of โ€œscpโ€ for the protocol (for example, in the distributionManagement pom.xml section). Then, the default SSH configuration for the computer is used (unix settings in ~ / .ssh).

 <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> 
0
source share

All Articles