Jsch session Configuration

12,642

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.

Share:
12,642
rogue-one
Author by

rogue-one

BY DAY: Alt-Rock Ninja Cowgirl at Veridian Dynamics. BY NIGHT: I write code and code rights for penalcoders.org, an awesome non-profit that will totally take your money at that link. My kids are cuter than yours. FOR FUN: C+ Jokes, Segway Roller Derby, NYT Sat. Crosswords (in Sharpie!), Ostrich Grooming. "If you see scary things, look for the helpers-you'll always see people helping."-Fred Rogers

Updated on July 04, 2022

Comments

  • rogue-one
    rogue-one almost 2 years

    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.