user2091559
user2091559

Reputation: 31

Always asking password while SCPing a file to Linux Server from a Windows machine using Maven 2.2:

I followed below steps:

  1. Created SSH key with userid ABC on windows machine using git bash.

  2. Copied public key to linux server with userid root:

    scp ~/.ssh/id_rsa.pub root@Linuxserver:~/.ssh/.

    It asked for a password and copied the file.

  3. SSH root@Linuxserver using git bash -> entered Linux server password -> logged in to linux server.

  4. Copied public key to authorized_keys in .ssh of Linux server:

    cat id_rsa.pub >> authorized_keys

  5. SSH root@Linuxserver using git bash -> logs in without asking for password

  6. SCP thru Maven doesn't work seamlessly and always asks for password. Even Linux root's password doesn't work and it keeps on asking for password again and again.

Below in Maven setting's file:

<server>
    <id>Linuxserver</id>
    <username>ABC</username>
    <privateKey>${user.home}/.ssh/id_rsa</privateKey>
    <filePermissions>664</filePermissions>
    <directoryPermissions>775</directoryPermissions>
    <configuration></configuration>
</server>

Below is excerpt from pom.xml:

<extensions>
      <extension>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-ssh</artifactId>
       <version>1.0-beta-6</version>
     </extension>
</extensions>

...

<plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>wagon-maven-plugin</artifactId>
      <version>1.0-beta-3</version>
      <configuration>
         <serverId>Linuxserver</serverId>
         <fromFile>${project.parent.basedir}/projectname/filename</fromFile>
         <url>scp://Linuxserver.com/testdirectory</url>
       </configuration>
       <executions>
         <execution>
           <id>upload-file-to-server</id>
           <phase>verify</phase>
           <goals>
             <goal>upload-single</goal>
           </goals>
         </execution>
       </executions>
</plugin>

I want SCP to happen without any user interaction. In nutshell, the problem seems to be Maven SCP not picking up the private key.

Upvotes: 1

Views: 2070

Answers (1)

ShadyKiller
ShadyKiller

Reputation: 710

Let us take an example :

localuser $ ssh [email protected]

Now SCP or SSH using checks two things(considering public key authorization):

  1. The private key of the using issuing the ssh command, usually ~/.ssh/id_rsa. In the example it would be /home/localuser/.ssh/id_rsa

  2. The public key of the user, in the ~/.ssh/authorized_keys file of the user you are loggin in as. In our e.g. at remote server it would be /home/remoteuser/.ssh/authorized_keys

I don't know much about Maven config but it seems like you are trying to login as ABC user, in which case ABC user should have the key of your localuser in it's authorized_keys file

Upvotes: 0

Related Questions