paulmiller3000
paulmiller3000

Reputation: 461

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?

Upvotes: 0

Views: 1613

Answers (2)

rjoyce
rjoyce

Reputation: 19

Sounds like your system doesn't allow for automatic hostkeys into the known_hosts file. You can check for the UpdateHostKeys flag in either your user, system, or potentially whatever user Jenkins runs under, SSH Config file. You can read more about the specific flag I'm talking about here.

If you need to add that hostkey manually, here's a nice write up for how to do it.

Upvotes: 0

apr_1985
apr_1985

Reputation: 1962

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

Upvotes: 1

Related Questions