Jsch session Configuration

rogue-one picture rogue-one · Aug 27, 2014 · Viewed 11.3k times · Source

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

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.

Answer

Kenster picture Kenster · Sep 4, 2014

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.

Here is a sample page listing 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.

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.