title: How do I automate Jenkins SSH credentials creation/assigning to nodes?
body: <p>I am writing an <em>automated Jenkins machine creation</em> script, and I have encountered a problem with SSH credentials, namely:</p>
  
  <p>In Jenkins there is a file called <code>credentials.xml</code> (in <code>/var/lib/jenkins</code>) which stored credentials for the nodes. Mine looks like so:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="credentials@1.18"&gt;
    &lt;domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash"&gt;
      &lt;entry&gt;
        &lt;com.cloudbees.plugins.credentials.domains.Domain&gt;
          &lt;specifications/&gt;
        &lt;/com.cloudbees.plugins.credentials.domains.Domain&gt;
        &lt;java.util.concurrent.CopyOnWriteArrayList&gt;
          &lt;com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl&gt;
            &lt;scope&gt;GLOBAL&lt;/scope&gt;
            &lt;id&gt;8743cc14-bc2c-44a6-b6bb-c121bef4ae2d&lt;/id&gt;
            &lt;description&gt;root_with_secret&lt;/description&gt;
            &lt;username&gt;root&lt;/username&gt;
            &lt;password&gt;2Xd4i7+8tjVXg2RHP6ggl/ZtWJp177ajXNajJxsj80o=&lt;/password&gt;
          &lt;/com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl&gt;
        &lt;/java.util.concurrent.CopyOnWriteArrayList&gt;
      &lt;/entry&gt;
    &lt;/domainCredentialsMap&gt;
  </code></pre>
  
  <p>There is (are) also nodes (slaves) configuration file(s) (stored in <code>/var/lib/jenkins/nodes/HOSTNAME/config.xml</code> for each slave) which look(s) like:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;slave&gt;
    &lt;name&gt;HOSTNAME_OF_MY_SECRET_MACHINE&lt;/name&gt;
    &lt;description&gt;HOSTNAME_OF_MY_SECRET_MACHINE&lt;/description&gt;
    &lt;remoteFS&gt;/root&lt;/remoteFS&gt;
    &lt;numExecutors&gt;1&lt;/numExecutors&gt;
    &lt;mode&gt;NORMAL&lt;/mode&gt;
    &lt;retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/&gt;
    &lt;launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="ssh-slaves@1.9"&gt;
      &lt;host&gt;10.0.10.1&lt;/host&gt;
      &lt;port&gt;22&lt;/port&gt;
      &lt;credentialsId&gt;8743cc14-bc2c-44a6-b6bb-c121bef4ae2d&lt;/credentialsId&gt;
      &lt;maxNumRetries&gt;0&lt;/maxNumRetries&gt;
      &lt;retryWaitTime&gt;0&lt;/retryWaitTime&gt;
    &lt;/launcher&gt;
    &lt;label&gt;&lt;/label&gt;
    &lt;nodeProperties/&gt;
    &lt;userId&gt;anonymous&lt;/userId&gt;
  &lt;/slave&gt;
  </code></pre>
  
  <p>The problem is that after I create the jenkins machine, copy <code>credentials.xml</code> and <code>config.xml</code>s for each slave then the credentials wouldn't work. I get </p>
  
  <pre><code>[07/26/15 16:00:39] [SSH] Opening SSH connection to 10.0.10.1:22.
  ERROR: Failed to authenticate as root. Wrong password. (credentialId:8743cc14-bc2c-44a6-b6bb-c121bef4ae2d/method:password)
  [07/26/15 16:00:41] [SSH] Authentication failed.
  hudson.AbortException: Authentication failed.
      at hudson.plugins.sshslaves.SSHLauncher.openConnection(SSHLauncher.java:1178)
      at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:701)
      at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:696)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  [07/26/15 16:00:41] Launch failed - cleaning up connection
  [07/26/15 16:00:41] [SSH] Connection closed.
  </code></pre>
  
  <p>To solve this issue I can go to <em>Jenkins</em> -> <em>Credentials</em> -> and then update the credential with the same password that I would use anyway and it will work.</p>
  
  <p>So the question is whether Jenkins uses kind of salting/hashing per installation so that the <code>credentials.xml</code> will not work if copied to a new machine?</p>