连接到Java主机后,如何读取SSH密钥-信号对标语(用于生成SSH密码)? [英] How to read the SSH key-sig pair banner (for generating SSH password) after connecting to host in Java?

查看:160
本文介绍了连接到Java主机后,如何读取SSH密钥-信号对标语(用于生成SSH密码)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在连接到Java中的远程主机后阅读SSH密钥-信号对横幅(用于生成SSH密码).我正在使用JSch客户端库进行SSH连接.

I want to read the the SSH key-sig pair banner (for generating SSH password) after connecting to a remote host in java. I'm using JSch client library for SSH connections.

在主机上进行某些操作后,SSH密码会更改,因此每次我需要从key-sig对生成新的SSH密码进行登录时.

The SSH password changes after certain operations on the host, hence each time I need to generate a new SSH password from the key-sig pair to login.

我可以通过编程方式阅读横幅吗?

Is there a way that I can read the banner programmatically?

下面是尝试通过客户端控制台(PuTTY)进行SSH时出现的key-sig对标题的摘录,其中包含密码提示.

Below is a snippet of the key-sig pair banner coming up with the password prompt when trying to SSH through client console (PuTTY).

NbwDZIAGjGS90zisB + jY9Kqrmu67PyMwas6S6jY68f + QL4l + TJDyHWUTGtzluflwY + Z/bHn0mXtdIkgxsoiVm5nCnNi0viMUKq/dPygXEZ0uDma9Co0WHI25UNLn525pNSuT1At5wTEEinH7xKiypIKDNVxxeprshtsd4rcirTUQveTBEbAgABJtzHrSNHmqs2Rui4NbWRqFDabft4uID6qwtl5wxAoNhh0Z9FT1r3kCK0FoLxcp9nlyQ6kD2rmp1sQG1SvQky2ATa9sD + ZBBAhlvwbOns5fWRE8A + ElQtkvyB8IxCS59cWa8T5rXm7G57x9uExEn57Vn3ZBuKP9Tg == bS6VdF5I167P03QMkM88k2cwS9KtyEfgT6Ff2e0iIvxdBMSKq453953J//vuriZk + mKjiEX0/RzrQSVIAzOYXFTtsZrIh7ER2IS0LoaXQ5izk4aobVq3BtiU + EknM3Qcy7IpVbwmQ7ZmCmjtOL +的Ux/n8vEDLYdk8dVeFJpzp4s53MrRkm4RC9yHgROW6HJxYscmQa + xah5ymRJyC2mt4aFfeQjAUZIEBhncLQge6nGEMybXmail1bgqhinE5xem + K6M2Ad3 + 0ahhW7NflWC4LjweTSHfsItfDwsb8i280LuYuw6w07LTadkn40AfpnVXOiFM + eUpUeIkw16RzduCew ==

NbwDZIAGjGS90zisB+jY9Kqrmu67PyMwas6S6jY68f+QL4l+TJDyHWUTGtzluflwY+z/bHn0mXtdIkgxsoiVm5nCnNi0viMUKq/dPygXEZ0uDma9Co0WHI25UNLn525pNSuT1At5wTEEinH7xKiypIKDNVxxeprshtsd4rcirTUQveTBEbAgABJtzHrSNHmqs2Rui4NbWRqFDabft4uID6qwtl5wxAoNhh0Z9FT1r3kCK0FoLxcp9nlyQ6kD2rmp1sQG1SvQky2ATa9sD+ZBBAhlvwbOns5fWRE8A+ElQtkvyB8IxCS59cWa8T5rXm7G57x9uExEn57Vn3ZBuKP9Tg== bS6VdF5I167P03QMkM88k2cwS9KtyEfgT6Ff2e0iIvxdBMSKq453953J//vuriZk+mKjiEX0/RzrQSVIAzOYXFTtsZrIh7ER2IS0LoaXQ5izk4aobVq3BtiU+EknM3Qcy7IpVbwmQ7ZmCmjtOL+Ux/n8vEDLYdk8dVeFJpzp4s53MrRkm4RC9yHgROW6HJxYscmQa+xah5ymRJyC2mt4aFfeQjAUZIEBhncLQge6nGEMybXmail1bgqhinE5xem+K6M2Ad3+0ahhW7NflWC4LjweTSHfsItfDwsb8i280LuYuw6w07LTadkn40AfpnVXOiFM+eUpUeIkw16RzduCew==

推荐答案

消息(您称为"SSH密钥-信号对横幅")可以作为SSH身份验证横幅或SSH键盘交互式身份验证提示出现.它不能是密码验证提示,因为它不能由SSH服务器自定义.

The message (which you call "SSH key-sig pair banner") can come either as an SSH authentication banner or as an SSH keyboard interactive authentication prompt. It cannot be a password authentication prompt, as that is not customizable by an SSH server.

在两种情况下,要捕获消息,请实现Session实例相关联. UserInfo-"rel =" nofollow noreferrer> Session.setUserInfo方法.

In both cases, to capture the message, implement the UserInfo interface. And associate it with the Session instance using the Session.setUserInfo method.

  • 要捕获身份验证横幅,请实现

  • To capture the authentication banner, implement the UserInfo.showMessage method. Note that the JSch calls that method for other (internal) messages too, not just for the banner. So you have to check, if you got the message you are looking for.

要捕获键盘交互提示,您的UserInfo实现还必须实现

To capture the keyboard interactive prompt, your UserInfo implementation has to implement also the UIKeyboardInteractive interface and its UIKeyboardInteractive.promptKeyboardInteractive method. The message can come in name, instruction or prompt arguments. You have to find out yourself.

要快速测试服务器如何发送消息,请尝试连接 WinSCP SFTP客户端,并检查其如何运行显示消息.

To quickly test how the server is sending the message, try to connect with WinSCP SFTP client and check how it displays the message.

或作为键盘交互式提示?

标题中的服务器提示" name中的内容. instruction将呈现在使用键盘交互式身份验证" 下面(此提示中没有说明").而挑战是..." prompt[0](在这种情况下,只有一个提示",但可以有更多提示).

The "Server Prompt" in the title is what you get in the name. The instruction would be rendered below the "Using keyboard-interactive authentication" (there are no "instructions" on this prompt). And the "The challenge is ..." is the prompt[0] (there's just one "prompt" in this case, but there can be more).

这篇关于连接到Java主机后,如何读取SSH密钥-信号对标语(用于生成SSH密码)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆