java Jsch 会话配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25526025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jsch session Configuration
提问by rogue-one
I have the following as shown below in my ssh config file. I will have to set the same configuration to my Jsch session. Jsch supports setting configs as below
我的 ssh 配置文件中有如下所示。我将不得不为我的 Jsch 会话设置相同的配置。Jsch 支持设置配置如下
session.setConfig(String name, String value);
session.setConfig(HashTable config);
session.setConfig(Properties config);
But none doesn't seems to support hierarchal nested setting (i.e Settings applicable only for a range of Hosts)
但是似乎没有一个不支持分层嵌套设置(即设置仅适用于一系列主机)
Host git.*
User git
ProxyCommand ssh -q github.example.com nc git %p
Open to alternative suggestions such as creating SSH Tunnels or others.
接受替代建议,例如创建 SSH 隧道或其他建议。
回答by Kenster
You may be suffering under a misapprehension that Jsch is a java version of the ssh
command-line utility. Jsch is an implementation of the SSH protocol. You could use it to build a command-line utility, but it doesn't implement every feature of the command-line utility that's not related to the protocol itself.
您可能会误认为 Jsch 是ssh
命令行实用程序的 Java 版本。Jsch 是 SSH 协议的一个实现。您可以使用它来构建命令行实用程序,但它不会实现与协议本身无关的命令行实用程序的所有功能。
Here is a sample pagelisting the config options which Jsch accepts. One thing you'll notice is that the list doesn't look anything like the ssh config options. If you want to support ssh-style options, you will probably find it necessary to write your own code to interpret and implement them.
这是一个示例页面,列出了 Jsch 接受的配置选项。您会注意到的一件事是该列表看起来与 ssh config options 完全不同。如果您想支持 ssh 样式的选项,您可能会发现有必要编写自己的代码来解释和实现它们。
To implement host-specific options, your client program would have to know which host it is connecting to and which options should be applied to that host.
要实现特定于主机的选项,您的客户端程序必须知道它连接到哪台主机以及应将哪些选项应用于该主机。
Regarding the default user, the remote username is a parameter that your code would supply to Jsch when calling the function to open an SSH session. If you want to have a default user feature, you'd have to write that feature into your code.
对于默认用户,远程用户名是您的代码在调用函数以打开 SSH 会话时将提供给 Jsch 的参数。如果您想拥有默认用户功能,则必须将该功能写入您的代码中。