title: How to provide Host Key for Maven SSH usage in server.xml
body: <p>In the Maven <code>settings.xml</code>, I want to define an SSH server and provide:</p>
  
  <ul>
  <li>The Host to connect to</li>
  <li>The user to connect to</li>
  <li>The location of a private key (to authenticate myself)</li>
  <li>Manually provide a Host Key (public key to verify the server)</li>
  </ul>
  
  <p>I do not want:</p>
  
  <ul>
  <li>to depend on the <code>~/.ssh/known_hosts</code> file</li>
  <li>to be asked to accept a host key</li>
  <li>to ignore the host key validation</li>
  </ul>
  
  <p>As such, existing answers on StackExchange do not help me, which include:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2685988/how-to-avoid-maven-builds-stall-on-ssh-host-authenticity-problem?lq=1">Overridding the provider to the <code>NullKnownHostProvider</code> and setting <code>hostKeyChecking</code> to <code>no</code></a>.</li>
  <li><a href="https://stackoverflow.com/questions/8323040/maven-wagon-scp-is-not-able-to-establish-a-connection">Manually executing ssh on the command line to get the hostkey entered in the <code>~/.ssh/known_hosts</code> file</a>.</li>
  </ul>
  
  <p>This is an example of how I envisioned it could be setup in the maven <code>setup.xml</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;servers&gt;
    &lt;server&gt;
      &lt;id&gt;gitcloud.myserver.net:8001&lt;/id&gt;
      &lt;username&gt;git&lt;/username&gt;
      &lt;privateKey&gt;C:/data/home/.ssh/id_rsa&lt;/privateKey&gt;
      &lt;configuration&gt;
        &lt;knownHostsProvider implementation="org.apache.maven.wagon.providers.ssh.knownhost.SingleKnownHostProvider"&gt;
          &lt;hostKeyChecking&gt;yes&lt;/hostKeyChecking&gt;
          &lt;contents&gt;codecloud.web.att.com ssh-rsa XXXXA3NvvFakeSSHKEYsdfADA...doLQ==&lt;/contents&gt;
        &lt;/knownHostsProvider&gt;
      &lt;/configuration&gt;
    &lt;/server&gt;
  &lt;/servers&gt;
  </code></pre>