Last week Wilfred and I spent some time to understand why the Maven2 mvn site:deploy command would not work when scp was used to access the target server. Based on the documentation we put:

<servers>
  <server>
    <id>server-id</id>
    <username>gumpy</username>
    <password>hushhush</password>
  </server>
</servers>
in the ~/.m2/settings.xml file and included
<distributionManagement>
  <site>
    <id>server-id</id>
    <name>Deployment Server</name>
    <url>scp://server-id.domain.com/home/gumpy/projects/</url>
  </site>
</distributionManagement>
in the projects POM. Looks OK, right? Well, while using commandline scp or ssh works using the credentials above, mvn site:deploy fails saying it cannot authenticate (and lists the supported authentication methods).

After a number of attempts we decided to try the private key authentication method in combination with an external scp command. This worked! It might not be what you want in the end, but at least we could continue. Small advantage of this solution might be that you don't have to include a password in your ~/.m2/settings.xml file. On the other hand, everybody who wants to deploy the site has to get their public key included in the servers ~/.ssh/authorized_keys file, which might be a disadvantage.

Here's the settings.xml snippet:

<servers>
  <server>
    <id>server-id</id>
    <username>gumpy</username>
  </server>
</servers>
And this is the projects POM snippet (note that scpexe indicates that an external scp command must be used):
<distributionManagement>
  <site>
    <id>server-id</id>
    <name>Deployment Server</name>
    <url>scpexe://server-id.domain.com/home/gumpy/projects/
  </site>
</distributionManagement>
<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
      <artifactId>wagon-ssh-external</artifactId>
      <version>1.0-alpha-5</version>
    </extension>
  </extensions>
...
</build>
In addition to these changes to the settings.xml and the projects POM file we had to include the SSH public key of our development machines in the .ssh/authorized_keys2 file of the "gumpy" user on the server.domain.com machine. A howto for "SSH without a password can be found here.

I suspect that the above is just a temporary workaround till the Maven 2 site:deploy plugin is fixed.

8 comments:

  1. Gero said...

    Thank you for posting this! It was very helpful. Maven's documentation is so sparse and I couldn't find the solution on the mailing lists. Bless you and Google.

    Cheers,
    Andrew
    Note: Comment imported. Original by Andrew Sterling Hanenkamp ( email: andrew.hanenkamp@boomer.com website: http://andrew.sterling.hanenkamp.com/ ) at 2006-05-08 22:34  

  2. Gero said...

    Thank you for explaining this! I was struggling with Maven 2.0.4 and your blog entry was very helpful.

    Note: Comment imported. Original by Anonymous at 2006-05-13 04:13  

  3. Gero said...

    If not mistaken,the password setting will not work because it is a bug in class ScpExternalWagon.

    private Commandline createBaseCommandLine(boolean putty, String executable)
    {
    Commandline cl = new Commandline();
    cl.setExecutable(executable);
    if(privateKey != null)
    {
    cl.createArgument().setValue("-i");
    cl.createArgument().setFile(privateKey);
    }
    if(putty && password != null)
    {
    cl.createArgument().setValue("-pw");
    cl.createArgument().setValue(password);
    }
    if(putty)
    {
    cl.createArgument().setValue("-batch");
    } else
    {
    cl.createArgument().setValue("-o");
    cl.createArgument().setValue("BatchMode yes");
    }
    return cl;
    }

    The scp command was set to batch mode.
    When scp was set to batch mode, this will prevent asking for password or passphase.


    Note: Comment imported. Original by Anonymous at 2006-06-13 09:31  

  4. Gero said...

    Thanks for your information. On my system only the ~/.ssh/id_dsa.pub key seems to work. I first tried ~/.ssh/id_rsa.pub keys, wich always ended up with errors.

    system:ubuntu 6.06maven 2.0.4
    Note: Comment imported. Original by Anonymous at 2006-06-28 14:00  

  5. Gero said...

    I got password authentication working by setting

    PasswordAuthentication yes

    in the sshd configuration.
    Note: Comment imported. Original by Anonymous at 2006-07-26 23:28  

  6. Gero said...

    Thanks for this article. I came up with a similar solution. However, whatever I try to deploy, the SSH connecion always freezes like that:

    [INFO] [deploy:deploy]altDeploymentRepository = nullUploading: scp://pc211828/var/www/proximity/inhouse/storage/groupId/artifactId/0.1/artifactId-0.1.jar2K uploaded[INFO] Retrieving previous metadata from inhouse [INFO] Uploading project information for test-unuseddependency 0.1

    Does anyone know what I should do?
    Note: Comment imported. Original by Régis ( email: regis.decamps@banque-france.fr website: null ) at 2007-07-24 09:37  

  7. Gero said...

    If you want to use scp:// you need to define
    <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh</artifactId> <version>1.0-beta-2</version> </extension> </extensions>
    Note: Comment imported. Original by Régis ( email: regis.decamps@banque-france.fr website: null ) at 2007-07-24 09:44  

  8. Olaf said...

    Hi there

    Apparently there are still issues with this until today:
    When using scpexe://..., the element of the settings.xml may not have an effect (just had this with maven 2.2.0 and the 2.0.1 maven-site-plugin Version). However, using scp:// (and thus the wagon java scp implementaion) uses the and seems to work fine now.  

Post a Comment