"reject HostKey" when connecting to a remote host via jumphost with JSch

SSH required for destination host via jumphost. Tried the same in the JSch JumpHosts example .

Session[] sessions = new Session[2];
Session session = null;

sessions[0] = session = jsch.getSession(getUserName(), "jumphost1.com", 22);
session.setPassword(getHostPassword());
UserInfo userInfo = new UserInfo();
userInfo.setPassword(getHostPassword());
session.setUserInfo(userInfo);
Properties prop = new Properties();
prop.put("StrictHostKeyChecking", "no");
prop.put("PreferredAuthentications", "publickey,keyboard-interactive,password");
session.setConfig(prop);
session.connect();

String host = "host1.com";
int assignedPort = session.setPortForwardingL(0, host, 22);
LOGGER.info("Jump host the {} of agent {} and port forwarding {}", i, host, assignedPort);

sessions[i] = session = jsch.getSession(getUserName(), "127.0.0.1", assignedPort);
session.setPassword(getHostPassword());
userInfo = new UserInfo();
userInfo.setPassword(getHostPassword());
session.setUserInfo(userInfo);
session.setHostKeyAlias(host);
session.connect();

When connecting to the target host, the exception becomes lower:

Caused by: com.jcraft.jsch.JSchException: reject HostKey: 127.0.0.1
    at com.jcraft.jsch.Session.checkHost(Session.java:799)
    at com.jcraft.jsch.Session.connect(Session.java:345)
    at com.jcraft.jsch.Session.connect(Session.java:183)

I am trying to enter the hosting host1.comthroughjumphost1.com

  • enter jumphost1.com
  • then ssh host1.com
  • run the commands in host1
+5
source share
1 answer

Your code to connect via jumphost is correct.

The only problem is that your local host key repository contains a different host key for the second host than the one you get from the real (second) host.

, StrictHostKeyChecking=no jumphost ( !). , , .

. Java UnknownHostKey SFTP JSch?

+4

Source: https://habr.com/ru/post/1692583/


All Articles