gpt4 book ai didi

java - JSch:从跳转服务器登录到目标服务器。跳转服务器要求输入 key 的密码,该 key 接受空字符串

转载 作者:行者123 更新时间:2023-12-02 13:37:29 26 4
gpt4 key购买 nike

这就是我尝试从跳转服务器连接到目标服务器时的样子。

SSH Screen

首先,它提示我输入跳转服务器的用户名和密码。登录后,我尝试连接到目标服务器。这就是密码提示出现的地方。我所需要做的就是在提示输入密码时按 Enter 键,系统将提示我输入密码。

这是我的代码片段:

    Session jumpServerSession = jsch.getSession(jumpServerHostUsername, jumpServerHostName, 22);
jumpServerSession.setPassword(jumpServerPassword);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
jumpServerSession.setConfig(config);
jumpServerSession.connect();

int assinged_port = jumpServerSession.setPortForwardingL(0, targetServerHostname, 22);
System.out.println("portforwarding: "+
"localhost:"+assinged_port+" -> "+targetServerHostname+":"+22);
//Main server connection session started
Session targetServerSession = jsch.getSession("root", targetServerHostname, 22);

targetServerSession.setHostKeyAlias(targetServerHostname);

targetServerSession.setPassword(targetServerPassword);
targetServerSession.setIdentityRepository(null);

java.util.Properties config1 = new java.util.Properties();
config1.put("StrictHostKeyChecking", "no");
targetServerSession.setConfig(config1);
targetServerSession.connect();

Error Message

正如您从上面的控制台输出中看到的,连接超时,这并不奇怪,因为我找不到发送空密码的方法。我用谷歌搜索了很多,找到了一些文章(使用机器人并将配置设置为“PreferredAuthentications”,“publickey,keyboard-interactive,password”)。他们不适合我。最后,我也无法从跳转服务器下载 key 。任何帮助将不胜感激!谢谢!

编辑:抱歉。我没有足够的声誉来发布图像。

最佳答案

如果私钥未加密,则 JSch 中无任何操作。它只会使用 key 。

但我没有看到您在任何地方指定您的私钥。如果您希望本地 JSch 以某种方式神奇地使用跳转服务器上的 .ssh/id_da key ,那么它不会。 JSch 甚至不知道跳转服务器的存在。您需要本地计算机上的私钥并让 JSch 知道它。

关于java - JSch:从跳转服务器登录到目标服务器。跳转服务器要求输入 key 的密码,该 key 接受空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42910229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com