title: Why I am getting error 'Server rejected the 1 private key' error on setting up ssh-slave docker image
body: <p>I am running both jenkins master and slave as docker containers by using jenkins/jenkins:lts and jenkins/ssh-slave image on Ubuntu. Following are the steps:</p>
  
  <ul>
  <li>Ran <code>ssh-keygen</code> inside the jenkins-master container(<code>docker exec -it container_id bash</code>) to generate the ssh keys</li>
  <li>Added the generated public key to authorized_keys file inside ssh-slave container using dockerfile</li>
  <li>Added private key inside Jenkins credentials as per this <a href="https://devopscube.com/setup-slaves-on-jenkins-2/" rel="nofollow noreferrer">link</a> </li>
  </ul>
  
  <p>I have looked at many questions related to this issue on stackoverflow but I am stuck with following error:</p>
  
  <p><em>[02/08/19 20:31:06] [SSH] Opening SSH connection to ###.##.#.#:22.
  [02/08/19 20:31:06] [SSH] SSH host key matches key in Known Hosts file. Connection will be allowed.
  <strong>ERROR: Server rejected the 1 private key(s) for jenkins (credentialId:worker-ssh/method:publickey)
  [02/08/19 20:31:06] [SSH] Authentication failed.
  Authentication failed.</strong>
  [02/08/19 20:31:06] Launch failed - cleaning up connection
  [02/08/19 20:31:06] [SSH] Connection closed.</em></p>
  
  <p><strong>Slave Template in Jenkins:</strong></p>
  
  <p><strong>Name</strong>: jenkins-worker</p>
  
  <p><strong>Usage</strong>: Use this node as much as possible</p>
  
  <p><strong>Launch method</strong>: Launch agent via SSH</p>
  
  <p><strong>Hostname</strong>: my ip extracted from ifconfig</p>
  
  <p><strong>Host key verification startegy</strong>: known hosts file verification strategy (.ssh/known_hosts contains entry for host ip provided)</p>
  
  <p>Dockerfile for ssh-slave</p>
  
  <pre><code>    #Docker version 18.09.1
      FROM jenkins/ssh-slave
      COPY /.ssh/id_rsa.pub /.ssh/authorized_keys
      RUN chmod 744 /.ssh/authorized_keys
  </code></pre>