java - Configuring known_hosts in jgit -


using jgit gitolite source control, have application generates code on command , want committed source control. goal pull fast forward, commit new code, , push it.

i have following method:

private void committogitrepository(string updatecomment, config config)       throws ioexception, nofilepatternexception, gitapiexception {    if(git == null)    {       git = git.open(new file(config.getdpucheckoutdir()));    }    pullcommand pull = git.pull();    pull.call(); } 

this method fails on pull.call() method call, following exception:

com.jcraft.jsch.jschexception: unknownhostkey: www.somehost.com. rsa key fingerprint 9d:92:a9:c5:5d:cb:5f:dc:57:ff:38:7e:34:31:fe:75 @ com.jcraft.jsch.session.checkhost(session.java:748) @ com.jcraft.jsch.session.connect(session.java:319) @ org.eclipse.jgit.transport.jschconfigsessionfactory.getsession(jschconfigsessionfactory.java:116) @ org.eclipse.jgit.transport.sshtransport.getsession(sshtransport.java:121) @ org.eclipse.jgit.transport.transportgitssh$sshfetchconnection.<init>(transportgitssh.java:248) @ org.eclipse.jgit.transport.transportgitssh.openfetch(transportgitssh.java:147) @ org.eclipse.jgit.transport.fetchprocess.executeimp(fetchprocess.java:136) @ org.eclipse.jgit.transport.fetchprocess.execute(fetchprocess.java:122) @ org.eclipse.jgit.transport.transport.fetch(transport.java:1104) @ org.eclipse.jgit.api.fetchcommand.call(fetchcommand.java:128) @ org.eclipse.jgit.api.pullcommand.call(pullcommand.java:245) @ net.intellidata.dpu.controller.schema.entitymappingcontroller.committogitrepository(entitymappingcontroller.java:149) ... (truncated meets code) 

the way read this, seems it's not finding known_hosts file in user_home/.git. however, i've been searching hour , i'm not finding way configure jgit tell jsch known_hosts file.

suggestions? know entry origin present in known_hosts file

this answer mentions:

jsch.setknownhosts("c:\\users\\ausername\\known_hosts"); 

but using jgit, , not jsch (the java secure shell) directly, let's see:

c:\users\vonc\prog\git>git clone https://github.com/eclipse/jgit cloning 'jgit'... remote: counting objects: 37854, done. remote: compressing objects: 100% (7743/7743), done. remote: total 37854 (delta 22009), reused 34367 (delta 18831) receiving objects: 100% (37854/37854), 6.73 mib | 1.37 mib/s, done. resolving deltas: 100% (22009/22009), done.  c:\users\vonc\prog\git>cd jgit  c:\users\vonc\prog\git\jgit>grep -nrhi "setknownhosts" * org.eclipse.jgit/src/org/eclipse/jgit/transport/jschconfigsessionfactory.java:262:                              sch.setknownhosts(in); 

found it!

this comes jschconfigsessionfactory.java#knownhosts(), , looks like:

new file(new file(home, ".ssh"), "known_hosts"); # with: home = fs.userhome(); 

userhome based on system.getproperty("user.home").

so make sure java session has user.home defined, , have %userprofile%/.ssh/known_hosts file in there.

(user.home should set java %userprofile% windows, is, if on windows: in case, this won't work).


now if do have %userprofile%/.ssh/known_hosts, then, mentioned here

just ssh client (using command-line ssh tool), add entry ~/.ssh/known_hosts file.


in case, stormehawke mentions in the comments:

since i'm running in tomcat windows service, jsch (and extension jgit) looking not in user folder in system account's home folder .ssh folder.
in case went ahead , copied .ssh folder system home folder since tomcat runs on machine development , testing purposes (probably not best security policy risk minimal in case).

from this question, this one, directory localsystem account should be:

c:\documents , settings\default user # or wind7 / 2008 c:\windows\system32\config\systemprofile 

the op mentions:

according call:

 system.out.println(system.getproperty("user.home"));  

the default system home directory windows7 (and presumably other nt-based windows system) c:\.
(so not ideal, quick fix, works).


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -