Saturday, June 2, 2007

Per user server authentication

The problem:

Each user has their own username and password for network machines that are accessed by Maven when deploying artifacts, websites, or maybe some other files. You wouldn't want this type of information in your project pom.xml so what do you do?

The solution:

The settings.xml file in your {HOME_DIR}/.m2* folder is your ticket. You can define servers and for each one define your username and password. Note that each server entry must have an id that matches with the one defined in the distribution management or other part of your pom.xml. Here is the example:
<settings>
<servers>
<server>
<id>hood</id>
<username>ottaway</username>
<password>Cm0nkeyz</password>
<privateKey>/Users/ottaway/.ssh/known_hosts</privateKey>
</server>
</servers>
</settings>
You should fill in the username, password and path to keys. On my Mac the path to ssh keys is /Users/ottaway/.ssh/known_hosts. You will need to do a little investigation on this if using a Windows machine. Please let me know if you figure it out.

* This is /Users/{username} on Macs, Documents and Settings/{username} on Windows or /home/{username} on most linux machines.