Jenkins Controller-Agent: Key exchange was not finished, connection is closed
Asked Answered
I

5

6

I want to connect a Jenkins agen to a Jenkins controller, but when trying to connect i'm getting following Error:

[05/02/18 15:26:59] [SSH] Opening SSH connection to <IP>
Key exchange was not finished, connection is closed.
java.io.IOException: There was a problem while connecting to <IP>:22
    at com.trilead.ssh2.Connection.connect(Connection.java:818)
    at hudson.plugins.sshslaves.SSHLauncher.openConnection(SSHLauncher.java:1324)
    at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:831)
    at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:820)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Key exchange was not finished, connection is closed.
    at com.trilead.ssh2.transport.KexManager.getOrWaitForConnectionInfo(KexManager.java:93)
    at com.trilead.ssh2.transport.TransportManager.getConnectionInfo(TransportManager.java:230)
    at com.trilead.ssh2.Connection.connect(Connection.java:770)
    ... 7 more
Caused by: java.io.IOException: Cannot negotiate, proposals do not match.
    at com.trilead.ssh2.transport.KexManager.handleMessage(KexManager.java:405)
    at com.trilead.ssh2.transport.TransportManager.receiveLoop(TransportManager.java:777)
    at com.trilead.ssh2.transport.TransportManager$1.run(TransportManager.java:489)
    ... 1 more
[05/02/18 15:26:59] Launch failed - cleaning up connection
[05/02/18 15:26:59] [SSH] Connection closed.

Configuration for Node:

  • Start-Method: Start agent over SSH
  • Hostname: is the IP
  • Access Data: user I created for SSH Access - > public key is in authorized keys on agent node

If I am on my the controller as user "jenkins" and do a ssh jenkins@<IP> i can login without problems (public key is on agent).

Why it doesn't work for "UI-Jenkins".

Jenkins-Version: 1.658

Node: Ubuntu 14.04

SSH-Slave Plugin: 1.26

Inextricable answered 2/5, 2018 at 13:39 Comment(0)
I
4

That "solved" the issue:

"Workaround is by commenting out MACs and KexAlgorithm line in /etc/ssh/sshd_config of Jenkins agent and restarting the sshd (service ssh restart on Ubuntu)

UPDATE: the issue has been resolved as of 2017-04-29

Jenkins controller fails to connect to the agent over SSH

Inextricable answered 4/5, 2018 at 8:21 Comment(2)
Additionally: you may have to uncheck "Require manual verification of initial connection" in the configuration of the agent.Abaddon
What if one doesn't even have these two settings in sshd_config?Brittan
S
1

Thought I'd throw my experience in this thread: my environment had a Windows master and mixed Windows and Linux agents. One Windows agent refused to connect to master, even after Master pushed 'jenkins-agent' and the other supporting files to the agent.

This agent had 6 different versions of the JDK and JRE installed. I uninstalled all of them, reinstalled only the latest JDK we needed, and set JAVA_HOME. This fixed the connectivity issue.

Scandal answered 19/6, 2020 at 13:8 Comment(0)
F
0

Execute this command on destination node.

sudo -i su -c 'sed -i -e "s/MACs /MACs hmac-sha1,/g" /etc/ssh/sshd_config; service sshd restart'

Forbearance answered 3/9, 2018 at 7:3 Comment(0)
U
0

Just recently run into this issue with docker

Find the Java Path

/home/jenkins # which java
/opt/java/openjdk/bin/java

Export the Java Path. In this case I am using the docker-compose

...
  exp_agent:
    image: jenkins/ssh-agent:alpine
    restart: always
    environment:
      JENKINS_AGENT_SSH_PUBKEY: $ENV_JENKINS_AGENT_SSH_PUBKEY
      JAVA_HOME: $ENV_JAVA_HOME
    container_name: jenkins-ssh-agent
    ports:
      - 22:22
    networks:
      - jenkins
...

The master still complains about the path of Java as /opt/java/openjdk/bin/java is not among the expected paths

...
[12/04/21 11:44:07] [SSH] Checking java version of /usr/bin/java
...

Create a symbolic link between the java path and one of the expected paths in the docker container (This could be automated in a Dockerfile)

ln -s /opt/java/openjdk/bin/java /usr/bin/java
Uriel answered 4/12, 2021 at 12:1 Comment(0)
B
0

had the same issue, solved by adding the SSH fingerprint of the slave to the master.

run this command from the master:

ssh-keyscan -H <SLAVE_IP/SLAVE_HOSTNAME> >> /var/lib/jenkins/.ssh/known_hosts

or whatever known_hosts file path displays from the log output

Buckie answered 9/10, 2023 at 17:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.