我是靠谱客的博主 安详大白,最近开发中收集的这篇文章主要介绍java 创建ssh用户秘钥,连接到Java主机后如何读取SSH密钥-信号对标语(用于生成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.

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?

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==

解决方案

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.

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.

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.

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

muhm4.png

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用户秘钥,连接到Java主机后如何读取SSH密钥-信号对标语(用于生成SSH密码)?...的全部内容,希望文章能够帮你解决java 创建ssh用户秘钥,连接到Java主机后如何读取SSH密钥-信号对标语(用于生成SSH密码)?...所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部