java - How to SSH to a server behind another SSH server using JSch? -


i need able ssh java program remote server, , there ssh server. have credentials both servers on client.

the commands passed automatically within app regular strings (no user input). need able run custom commands on second server , able decide commands issue during runtime, based on output , simple logic.

can use jsch , if yes, should start into? (examples, info)

=============================================================

added:

exception in thread "main" com.jcraft.jsch.jschexception: unknownhostkey: host.net. rsa key fingerprint 'blahblahblah'

as till now, solving problem modifying known_hosts file , adding host manually in there. can bypass little problem settings option somewhere telling jsch press yes automatically when yes-no question asked?

to connect second server behind firewall, there in principle 2 options.

the naive 1 call ssh on first server (from exec channel), indicating right server. need agent forwarding jsch, , doesn't provide jsch api access second server, ssh command line.

the better 1 use connection first server build tcp tunnel, , use tunnel connect second server. jsch wiki contains proxyssh class (together example code) allows use jsch session tunnel second jsch session. (disclaimer: class written me, support jsch author.)

when have connection second server, use either shell channel or series of exec channels execute commands. (see shell, exec or subsystem channel in jsch wiki overview, , javadocs details.)


for unknown-host-key problem:

the secure version collect host keys (in secure way) before , put them in known_hosts file. (if trust key presented you, vulnerable man-in-the-middle attack. if these of no concern in network, since physically secured, you.)

the convenient version setting configuration option stricthostkeychecking no - add unknown host keys host keys file:

jsch.setconfig("stricthostkeychecking", "no"); 

(you can set individually on sessions, if want set proxied sessions , not tunnel session. or override tunnel session yesor ask - there mitm danger might greater.)

a middle way enable asking user (which should compare fingerprints list) - this, implement userinfo interface , provide object session. (the jsch wiki contains example implementation using swing joptionpanes, can use if client program runs on system gui.)

for saving of accepted host keys work, must use jsch.setknownhosts method file name argument, not 1 inputstream argument - else accepting have repeated each restart of client.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -