security - How to get SSH input/output from single command (ssh exec) in Java (current: sshj)? -


tl;dr: how can i/o when sending exec command using sshj? alternatively, other java ssh libraries provide similar level of abstraction might work better use case?

apart not working me, yet, sshj’s level of abstraction, other java/ssh libs lower level , neither want nor need use case.

details:

as part tool developer onboarding, i’m trying install ssh public keys on gitblit server, patterned after https://github.com/hierynomus/sshj/blob/master/examples/src/main/java/net/schmizz/sshj/examples/exec.java.

i’m working sshj:

compile 'com.hierynomus:sshj:0.21.1' 

platform: koltin 1.1.3-2 (jre 1.8.0_131-b11, azul zulu on mac 10.12)

unfortunately can’t seem read or write streams.

i cut down in repl, trying gitblits message:

import org.slf4j.logger import org.slf4j.loggerfactory import java.util.logging.level import java.util.logging.logmanager  fun sshclientwithtrustinghostkeyverifier(): sshclient {     return sshclient(defaultconfig()).also { client ->         client.addhostkeyverifier(object : opensshknownhosts(file(sshdir(), "known_hosts")) {             override fun hostkeyunverifiableaction(hostname: string?, key: publickey?): boolean {                 super.write(simpleentry(null, hostname, keytype.fromkey(key), key))                 return true             }         })     } }   logmanager.getlogmanager().let {lm -> lm.loggernames.assequence().foreach { lm.getlogger(it).apply{     level = level.finest     handlers.foreach { it.level = level.finest }}}}  val log: logger = loggerfactory.getlogger("foo")   log.debug("a") val client = sshclientwithtrustinghostkeyverifier() log.debug("b") client.connect("the.gitblit.local", 29418) log.debug("c") client.authpassword("my_account", "my super password") log.debug("d") val session = client.startsession() log.debug("e") val cmd = session.exec("keys --help") log.debug("f") log.debug(cmd.inputstream.readbytes().tostring()) log.debug("g") log.debug(cmd.errorstream.readbytes().tostring()) log.debug("h") cmd.join() log.debug("i") log.debug("exit status: {}", cmd.exitstatus) 

this produces lot of output, includes strange-sounding error "[protocol_error] received channel_success". posted full output on https://pastebin.com/d3y1tc8r.

if let sit, after while dies of timeout. no output ever materializes.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -