Search code examples
jenkinsamazon-ec2sshssh-keys

Jenkins cannot connect to EC2 using private key, but I can connect using Putty


I recently inherited a Jenkins instance running on an AWS EC2 server. It has several pipelines to different EC2 servers that are running successfully. I'm having trouble adding a new node to a new EC2 web server.

I have an account on that new web server named jenkins. I generated keys, added the ssh-rsa key to ~/.ssh/authorized_keys, and verified I was able to connect with the jenkins user via Putty.

enter image description here

In Jenkins, under Dashboard > Credentials > System > Global Credentials, I created new credentials as follows:

  1. Username: jenkins
  2. Private Key -> Enter Key Directly: Pasted in the key beginning with "BEGIN RSA PRIVATE KEY":

enter image description here

Finally, I created a new node using those credentials, to connect via SSH and use the "Known hosts file Verification Strategy."

enter image description here

Unfortunately, I'm getting the following error when I attempt to launch the agent:

[01/04/22 22:16:43] [SSH] WARNING: No entry currently exists in the Known Hosts file for this host. Connections will be denied until this new host and its associated key is added to the Known Hosts file. Key exchange was not finished, connection is closed.

I verified I have the correct Host name configured in my node. I don't know what I'm missing here, especially since I can connect via Putty.

Suggestions?


Solution

  • Have you added the new node to the known hosts file on the Controller node? I assume Putty was your local machine rather than the controller?

    See this support article for details https://support.cloudbees.com/hc/en-us/articles/115000073552-Host-Key-Verification-for-SSH-Agents#knowhostsfileverificationstrategy