Jenkins not connecting to agents via SSH?
If you've followed the guide in the Jenkins user handbook to connect Jenkins agents, you've likely used the command below to generate your SSH key pairs:
ssh-keygen -f ~/.ssh/jenkins_agent_key
However, to your dismay, launching the agent may lead to the following error:
ERROR: Server rejected the 1 private key(s) for jenkins (credentialId:jenkins/method:publickey)
ERROR: Failed to authenticate as jenkins with credential=jenkins
java.io.IOException: Publickey authentication failed.
You've probably tried troubleshooting by SSH-ing to the agent node from outside Jenkins (either from the host machine or the Jenkins controller container if you are using Docker) and successfully connecting. Despite these successful connections, the error persists when launching the node on the Jenkins UI.
If you're lucky, you may come across a Reddit post that provides a clue, leading you to the SSH Agents Plugin documentation. Here, you'll discover the recommended commands for generating supported keys:
ssh-keygen -f pemkey -m PEM -t rsa -b 4096
ssh-keygen -f pemkey -m PEM -t ed25519
ssh-keygen -f pemkey -m PEM -t dsa -b 1024
ssh-keygen -f pemkey -m PEM -t ecdsa -b 521
ssh-keygen -f ssh2key -m RFC4716 -t rsa -b 4096
ssh-keygen -f ssh2key -m RFC4716 -t ed25519
ssh-keygen -f ssh2key -m RFC4716 -t dsa -b 1024
ssh-keygen -f ssh2key -m RFC4716 -t ecdsa -b 521
It's not entirely clear why using default options for key type and bit size isn't working, or if this is deliberate, perhaps in pursuit of better security. However, what we do know is that the command provided on the Jenkins user handbook page isn't sufficient. Be sure to use the commands for supported keys from the SSH Agents Plugin documentation.
Thank you, and until next time!
Lead, Network & Security Specialist at Opentext | CISSP | PCCSE | MBA | SDG16
10 个月Well written