2

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:

  • Ran ssh-keygen inside the jenkins-master container (docker exec -it container_id bash) to generate the ssh keys
  • Added the generated public key to authorized_keys file inside ssh-slave container using dockerfile
  • Added private key inside Jenkins credentials as per this link

I have looked at many questions related to this issue on Stack Overflow but I am stuck with following error:

[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.
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.
[02/08/19 20:31:06] Launch failed - cleaning up connection
[02/08/19 20:31:06] [SSH] Connection closed.

Slave Template in Jenkins:

Name: jenkins-worker

Usage: Use this node as much as possible

Launch method: Launch agent via SSH

Hostname: my ip extracted from ifconfig

Host key verification startegy: known hosts file verification strategy (.ssh/known_hosts contains entry for host ip provided)

Dockerfile for ssh-slave

    #Docker version 18.09.1
    FROM jenkins/ssh-slave
    COPY /.ssh/id_rsa.pub /.ssh/authorized_keys
    RUN chmod 744 /.ssh/authorized_keys
3
  • "I added my private key in the credentials to ssh into the slave" - you need to add your public key to the authorized_keys file on the slave, not your private key.
    – jayhendren
    Commented Feb 10, 2019 at 21:33
  • I have added my public key in authorized_key folder at slave and private key as a credential to ssh on Jenkins. I have updated my question with clear description.
    – bot
    Commented Feb 11, 2019 at 14:31
  • chmod 744 on .ssh/authorized_keys I think would be bad. ssh will not use keys from files if permissions are too open. Change to 600. rw-------
    – gaoithe
    Commented May 31, 2019 at 16:34

1 Answer 1

1

chmod 744 on .ssh/authorized_keys I think would be bad. ssh will not use keys from files if permissions are too open.

Change permissions to 600. rw-------

   permissions of 744 == rwxr-xr-x   ==  read permissions for world and group

   permissions of 600 == rw-------   ==  read/write permissions for owner user only

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .