1
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
"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 – 2019-02-10T21:33:56.257
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 – 2019-02-11T14:31:55.360
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 – 2019-05-31T16:34:07.360