clj-commons / clj-ssh Goto Github PK
View Code? Open in Web Editor NEWSSH commands via jsch
SSH commands via jsch
I want to execute an SSH command which requires a '-t' option. How do I do this using this library?
Currently, with-connection executes it's body, even if the connection attempt fails. I'm not sure if an exception should be thrown, or some return value should be used to denote failure.
user=> (use 'clj-ssh.cli)
CompilerException com.jcraft.jsch.JSchException: java.io.FileNotFoundException: C:\Users\Tatu.ssh\known_hosts (The system cannot find the file specified), compiling:(cli.clj:39:15)
Creating an empty known_hosts fixes the issue.
I've come across this error/typo when trying to use :mkdir in version 0.2.0. :rmdir is declared an extra time, rather than :mkdir in file: clj-ssh/src/clj_ssh/ssh.clj
496: :rmdir (.rmdir channel (first args))
497: :rmdir (.mkdir channel (first args)) <===
498: :stat (.stat channel (first args)
Regards,
Andrew
with-connection does not currently allow a timeout specification for making a connection.
Can I use interactive mode for ssh from the REPL in some way? Couldn't find any example of this and I have a shell which only allows interactive mode.
/D
Sorry to bother you with a "support" question. Normal usage of this library works really great, thanks for that.
Now, I would like to stream ssh session output to stdout. I tried several variations of the below and I also tried examples I found on the web, but without luck.
(require '[clj-ssh.ssh :as s])
(require '[clj-ssh.cli :refer [ssh]])
(let [{shell :channel out-stream :out-stream} (ssh host :cmd "sleep 10; echo hi" :strict-host-key-checking :no :out :stream)]
(s/with-channel-connection shell (while (s/connected-channel? shell) (println "connected")) (println "nothing")))
Am I missing something?
Not sure if this is a bug or just something missing from the documentation, but when I do
(Let [agent (ssh-agent {})]
(let [session (session agent domain {:strict-host-key-checking :no})]
(with-connection session
(let [result (ssh session {:cmd "ls"})]
(println result)))))
things work fine, whereas when I do
(let [agent (ssh-agent {:use-system-ssh-agent false
:known-hosts-path "/Users/joachim/.ssh/known_hosts"})]
(add-identity agent {:private-key-path "/Users/joachim/.ssh/id_rsa"
:public-key-path "/Users/joachim/.ssh/id_rsa.pub"})
(let [session (session agent domain {:username "joachim" :strict-host-key-checking :no})]
(with-connection session
(let [result (ssh session {:cmd "ls"})]
(println result)))))
I get
JSchException USERAUTH fail com.jcraft.jsch.UserAuthPublicKey.start (UserAuthPublicKey.java:119)
(The private and public key paths provided are the same as used by the system ssh-agent)
I need to use an IdentityFile to ssh to my ec2 instance. Does clj-ssh support this?
I'm running this on OS/X El Capitan.
The code is simple:
(ssh/ssh-agent {})
It causes:
2. Unhandled com.jcraft.jsch.JSchException
fromBase64: invalid base64 data
Util.java: 63 com.jcraft.jsch.Util/fromBase64
KnownHosts.java: 218 com.jcraft.jsch.KnownHosts/setKnownHosts
KnownHosts.java: 54 com.jcraft.jsch.KnownHosts/setKnownHosts
JSch.java: 317 com.jcraft.jsch.JSch/setKnownHosts
ssh.clj: 151 clj-ssh.ssh/ssh-agent/fn
ssh.clj: 150 clj-ssh.ssh/ssh-agent
REPL: 22 node.upload.sftp/eval61527
Compiler.java: 6782 clojure.lang.Compiler/eval
Compiler.java: 6745 clojure.lang.Compiler/eval
core.clj: 3081 clojure.core/eval
main.clj: 240 clojure.main/repl/read-eval-print/fn
main.clj: 240 clojure.main/repl/read-eval-print
main.clj: 258 clojure.main/repl/fn
main.clj: 258 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 87 clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 630 clojure.core/apply
core.clj: 1868 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 85 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 222 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
interruptible_eval.clj: 190 clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
AFn.java: 22 clojure.lang.AFn/run
ThreadPoolExecutor.java: 1142 java.util.concurrent.ThreadPoolExecutor/runWorker
ThreadPoolExecutor.java: 617 java.util.concurrent.ThreadPoolExecutor$Worker/run
Thread.java: 745 java.lang.Thread/run
1. Caused by java.lang.ArrayIndexOutOfBoundsException
399
Util.java: 54 com.jcraft.jsch.Util/fromBase64
KnownHosts.java: 218 com.jcraft.jsch.KnownHosts/setKnownHosts
KnownHosts.java: 54 com.jcraft.jsch.KnownHosts/setKnownHosts
JSch.java: 317 com.jcraft.jsch.JSch/setKnownHosts
ssh.clj: 151 clj-ssh.ssh/ssh-agent/fn
ssh.clj: 150 clj-ssh.ssh/ssh-agent
REPL: 22 node.upload.sftp/eval61527
Compiler.java: 6782 clojure.lang.Compiler/eval
Compiler.java: 6745 clojure.lang.Compiler/eval
core.clj: 3081 clojure.core/eval
main.clj: 240 clojure.main/repl/read-eval-print/fn
main.clj: 240 clojure.main/repl/read-eval-print
main.clj: 258 clojure.main/repl/fn
main.clj: 258 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 87 clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 630 clojure.core/apply
core.clj: 1868 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 85 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 222 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
interruptible_eval.clj: 190 clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
AFn.java: 22 clojure.lang.AFn/run
ThreadPoolExecutor.java: 1142 java.util.concurrent.ThreadPoolExecutor/runWorker
ThreadPoolExecutor.java: 617 java.util.concurrent.ThreadPoolExecutor$Worker/run
Thread.java: 745 java.lang.Thread/run
How do I go round diagnosing the problem? Thank you so much!
UPDATE: It seems to have something to do with the contents of known_hosts (it's not been tampered and SSH works).
(Created from jepsen-io/jepsen#398)
Hey,
We're using Jepsen 0.1.14 which in turn uses clj-ssh-0.5.14
. Here's a stack trace I ran into:
WARN [2019-07-09 11:53:31,619] main - jepsen.core Test crashed!
java.lang.ArrayIndexOutOfBoundsException: -2
at clj_ssh.ssh$scp_receive_command$fn__2679.invoke(ssh.clj:874) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_receive_command.invokeStatic(ssh.clj:869) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_receive_command.invoke(ssh.clj:864) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_sink.invokeStatic(ssh.clj:980) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_sink.invoke(ssh.clj:977) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_from.invokeStatic(ssh.clj:1094) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_from.doInvoke(ssh.clj:1044) ~[jepsen-0.1.14.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:445) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.applyToHelper(AFn.java:160) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.applyTo(RestFn.java:132) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:667) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invoke(core.clj:660) ~[clojure-1.10.0.jar:na]
at jepsen.control$download$fn__2881.invoke(control.clj:227) ~[jepsen-0.1.14.jar:na]
at jepsen.control$download.invokeStatic(control.clj:227) ~[jepsen-0.1.14.jar:na]
at jepsen.control$download.doInvoke(control.clj:223) ~[jepsen-0.1.14.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:421) ~[clojure-1.10.0.jar:na]
at jepsen.core$snarf_logs_BANG_$fn__5395$fn__5414.invoke(core.clj:133) ~[jepsen-0.1.14.jar:na]
at jepsen.core$snarf_logs_BANG_$fn__5395.invoke(core.clj:132) ~[jepsen-0.1.14.jar:na]
at jepsen.control$on_nodes$fn__2918.invoke(control.clj:391) ~[jepsen-0.1.14.jar:na]
at clojure.lang.AFn.applyToHelper(AFn.java:154) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.applyTo(AFn.java:144) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:665) ~[clojure-1.10.0.jar:na]
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1973) ~[clojure-1.10.0.jar:na]
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1973) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.applyTo(RestFn.java:142) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:669) ~[clojure-1.10.0.jar:na]
at clojure.core$bound_fn_STAR_$fn__5734.doInvoke(core.clj:2003) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:408) ~[clojure-1.10.0.jar:na]
at dom_top.core$real_pmap_helper$build_thread__214$fn__215.invoke(core.clj:146) ~[jepsen-0.1.14.jar:na]
at clojure.lang.AFn.applyToHelper(AFn.java:152) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.applyTo(AFn.java:144) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:665) ~[clojure-1.10.0.jar:na]
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1973) ~[clojure-1.10.0.jar:na]
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1973) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:425) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.applyToHelper(AFn.java:156) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.applyTo(RestFn.java:132) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:669) ~[clojure-1.10.0.jar:na]
at clojure.core$bound_fn_STAR_$fn__5734.doInvoke(core.clj:2003) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:397) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.run(AFn.java:22) ~[clojure-1.10.0.jar:na]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
ERROR [2019-07-09 11:53:31,629] main - jepsen.cli Oh jeez, I'm sorry, Jepsen broke. Here's why:
java.lang.ArrayIndexOutOfBoundsException: -2
at clj_ssh.ssh$scp_receive_command$fn__2679.invoke(ssh.clj:874) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_receive_command.invokeStatic(ssh.clj:869) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_receive_command.invoke(ssh.clj:864) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_sink.invokeStatic(ssh.clj:980) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_sink.invoke(ssh.clj:977) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_from.invokeStatic(ssh.clj:1094) ~[jepsen-0.1.14.jar:na]
at clj_ssh.ssh$scp_from.doInvoke(ssh.clj:1044) ~[jepsen-0.1.14.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:445) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.applyToHelper(AFn.java:160) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.applyTo(RestFn.java:132) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:667) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invoke(core.clj:660) ~[clojure-1.10.0.jar:na]
at jepsen.control$download$fn__2881.invoke(control.clj:227) ~[jepsen-0.1.14.jar:na]
at jepsen.control$download.invokeStatic(control.clj:227) ~[jepsen-0.1.14.jar:na]
at jepsen.control$download.doInvoke(control.clj:223) ~[jepsen-0.1.14.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:421) ~[clojure-1.10.0.jar:na]
at jepsen.core$snarf_logs_BANG_$fn__5395$fn__5414.invoke(core.clj:133) ~[jepsen-0.1.14.jar:na]
at jepsen.core$snarf_logs_BANG_$fn__5395.invoke(core.clj:132) ~[jepsen-0.1.14.jar:na]
at jepsen.control$on_nodes$fn__2918.invoke(control.clj:391) ~[jepsen-0.1.14.jar:na]
at clojure.lang.AFn.applyToHelper(AFn.java:154) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.applyTo(AFn.java:144) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:665) ~[clojure-1.10.0.jar:na]
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1973) ~[clojure-1.10.0.jar:na]
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1973) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.applyTo(RestFn.java:142) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:669) ~[clojure-1.10.0.jar:na]
at clojure.core$bound_fn_STAR_$fn__5734.doInvoke(core.clj:2003) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:408) ~[clojure-1.10.0.jar:na]
at dom_top.core$real_pmap_helper$build_thread__214$fn__215.invoke(core.clj:146) ~[jepsen-0.1.14.jar:na]
at clojure.lang.AFn.applyToHelper(AFn.java:152) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.applyTo(AFn.java:144) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:665) ~[clojure-1.10.0.jar:na]
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1973) ~[clojure-1.10.0.jar:na]
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1973) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:425) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.applyToHelper(AFn.java:156) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.applyTo(RestFn.java:132) ~[clojure-1.10.0.jar:na]
at clojure.core$apply.invokeStatic(core.clj:669) ~[clojure-1.10.0.jar:na]
at clojure.core$bound_fn_STAR_$fn__5734.doInvoke(core.clj:2003) ~[clojure-1.10.0.jar:na]
at clojure.lang.RestFn.invoke(RestFn.java:397) ~[clojure-1.10.0.jar:na]
at clojure.lang.AFn.run(AFn.java:22) ~[clojure-1.10.0.jar:na]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
Is it possible to "su - root" , type password and then execute commands?
It will be nice if this is part of the documentation.
Is there a quiet mode (ssh -q) option?
I try to run command on remote machine, I success to connect through my MAC over ssh without password (use known_host
)
so I run through REPL
:
(let [agent (clj-ssh.ssh/ssh-agent {})]
(clj-ssh.ssh/add-identity agent {
:known-hosts-path "/Users/maxim/.ssh/known_hosts"
:private-key-path "/Users/maxim/.ssh/id_rsa"
:public-key-path "/Users/maxim/.ssh/id_rsa.pub"
})
(let [session (clj-ssh.ssh/session agent "ops-ev19.comp.com" {:username "maxim" :strict-host-key-checking :no})]
(clj-ssh.ssh/with-connection session
(let [result (ssh session {:cmd "ls"})]
(println (:out result))))))
and get error:
ClassCastException com.jcraft.jsch.Session cannot be cast to java.lang.String clj-ssh.ssh/session-impl (ssh.clj:318)
I use [clj-ssh "0.5.14"]
Any ideas?
FYI - Using [clj-ssh "0.5.11"]
and [org.clojure/clojure "1.8.0-beta1"]
I get the following compile error:
Exception in thread "main" java.lang.RuntimeException: Too many arguments to throw, throw expects a single Throwable instance, compiling:(clj_ssh/ssh.clj:297:13)
I don't want it to echo what I send.. I've got something like:
(ssh/with-connection nic-sesh
(let [ch (doto (ssh/shell-channel nic-sesh)
(.setPty true))
in (.getInputStream ch)
out (.getOutputStream ch)]
(ssh/with-channel-connection ch
(thread
(loop [char (.read in)] ; from ssh to stdout
(if (= -1 char)
(System/exit 1)
(do
(.write *out* char)
(.flush *out*)
(recur (.read in))))))
(loop [char (.read *in*)] ; from stdin to ssh
(if-not (= -1 char)
(do
(.write out char)
(.flush out)
(recur (.read *in*))))))))
it seems weird that I'd get an echo. Anyone have an explanation?
Is there a way to do this already?
at least :strict-host-key-checking is not honored in 'ssh', but is in 'session'.
jsch logs a lot at the INFO level. Please map jsch INFO to DEBUG and jsch DEBUG to TRACE.
(clj-ssh.ssh/sftp session {} :get "/remote/path" "/local/path/with spaces")
fails with com.jcraft.jsch.SftpException: No such file
give sshj http://github.com/shikhar/sshj/ a shot, it will keep you saner than jsch
my motives: ironing out bugs
The defaults for these options are low. See pallet/pallet#108.
hugod> aaelony: so it looks like there is an issue in that clj-ssh will not load the default key into the agent for you, and doesn't fall back to not using the agent if the connection with the agent fails
Hello, does this library support X11 port forwarding ?
Hi,
It seems that there is not ability to set available authentication methods and their order.
I have systems that use only keyboard-interractive and any public key auth ends with disconnection.
Every connection tries public key first and result is:
com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 2 publickey authentication rejected
We recently bumped into an unresponsive app (with no logs or stack traces). After thread dumping the app, the culprit seems to be an initial hanging read (which is common problem, see https://stackoverflow.com/questions/28785085/how-to-prevent-hangs-on-socketinputstream-socketread0-in-java). The hanging thread could reasonably die there, but this https://github.com/hugoduncan/clj-ssh/blob/develop/src/clj_ssh/ssh.clj#L400 lock prevents any other requests from that point forward. Is there a way to avoid global locking on the known-hosts file?
Here's the relevant bit of the thread dump:
"qtp1869210328-19" #19 prio=5 os_prio=0 tid=0x00007fb998801800 nid=0x1b runnable [0x00007fb9750d6000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.jcraft.jsch.IO.getByte(IO.java:82)
at com.jcraft.jsch.Session.read(Session.java:918)
at com.jcraft.jsch.UserAuthNone.start(UserAuthNone.java:85)
at com.jcraft.jsch.Session.connect(Session.java:389)
at com.jcraft.jsch.Session.connect(Session.java:183)
at clj_ssh.ssh$fn__6855.invokeStatic(ssh.clj:118)
at clj_ssh.ssh$fn__6855.invoke(ssh.clj:115)
at clj_ssh.ssh.protocols$fn__6813$G__6780__6822.invoke(protocols.clj:4)
at clj_ssh.ssh$connect.invokeStatic(ssh.clj:401)
- locked <0x0000000704fe13b0> (a java.lang.Object)
at clj_ssh.ssh$connect.invoke(ssh.clj:397)
I could see around 50 threads waiting for lock <0x0000000704fe13b0> to be released. We had to restart the app. Thanks
It reads:
(sftp channel :cd "/remote/path")
(sftp channel :put "/some/file" "filename")
but should be:
(sftp channel {} :cd "/remote/path")
(sftp channel {}:put "/some/file" "filename")
Jsch support the direct-tcpip channel type which allows to directly connect to tcp ports on the remote host through ssh.
It would be really nice if clj-ssh could provide a nice wrapper for that
Example code:
(ns clj-ssh-test.core
(:require [clj-ssh.cli :as ssh]))
(let [proc (ssh/ssh "localhost" "ls")]
proc) ;; returns ls output in :out
(let [proc (ssh/ssh "localhost" "ls" :out :stream)]
(println "start [" (slurp (:out-stream proc)) "]"))
;; Prints "start [ ]" ls response is not printed
I'm using Clojure 1.7.0-alpha1 and clj-ssh 0.5.10
If an error occurs during connection, the exception thrown includes the entire hosts
list, which in turn may have passwords and those passwords will be present in the stacktrace.
(fn [e s]
(throw
(ex-info
(str "Failed to connect "
(.getUserName s) "@"
(.getHost s) ":"
(.getPort s)
" " (pr-str (into [] (.getIdentityNames agent)))
" " (pr-str hosts))
{:hosts hosts}
e)))
The password could be removed from the exception message and data.
It took a fair amount of digging to find that setting the "PreferredAuthentications" option for creating a session allows you to change the auth type. It was defaulting to Kerberos for me.
Scroll down to "User Authentication Methods" for all of the options.
https://epaul.github.io/jsch-documentation/javadoc/com/jcraft/jsch/JSch.html#setConfig-java.lang.String-java.lang.String-
Hello,
Is there any way to do this
(let [agent (ssh-agent {})]
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
(with-connection session
(let [result (ssh session {:cmd "export TEST=1"})]
(println (result :out)))
(let [result (ssh session {:cmd "echo $TEST"})]
(println (second result)))))))
and the echo $TEST equals to 1? I tried the last code but the result of last print is empty. Is there any way to use the same session?
I am not sure under what circumstances this occurs but I've seen what appears to be transmission characters corrupting larger files when transferred to some, but not all, SFTP servers. In the case I saw this was on > 500Kbyte files (but may occur on smaller) being transferred to a MOVEit Transfer SFTP server, version 12.0.2.149.
This appears to be a bug in the underlying JSch library in version 0.1.53 or earlier. See the JSch release notes here: http://www.jcraft.com/jsch/ChangeLog
I have tried bumping the version of JSch to 0.1.55 in my codebase and this appears to resolve the issue although I have not fully tested all the features of clj-ssh under that version.
I have a project that includes [slingshot "0.9.0"]
When I also include [clj-ssh "0.3.1-SNAPSHOT"], and load my namespace, (use 'myns.core), I get this:
java.io.FileNotFoundException: Could not locate slingshot/core__init.class or slingshot/core.clj on classpath: (ssh.clj:1)
I'm guessing the public interface to slingshot changed somewhere along the line.
Would this be a big effort to update?
I may try to take a look myself later tomorrow.
Hey this is my first time using this library, ive heard pretty good things about it.
I am trying to execute the following command:
(sftp "host" :put file "/" :username "user" :password "password" :port port_no)
but the following error gets thrown:
No matching method found: put for class com.jcraft.jsch.ChannelSftp
if i manually execute sftp
from the command line and type the password all works as expected, however I can't figure out why this isn't working.
I am using version 0.5.11
hopefully its something trivial.
https://github.com/mwiede/jsch is actively updated and has some fixes and features, notably ed25519 keys.
I'm just trying to convert this:
"ssh -L 3306:remote-mysql-host:3306 bastion"
to the equivalent ssh-clj code, so I was trying something like this:
(def agent (ssh/ssh-agent {}))
(def session (ssh/session agent
"bastion-host"
{:user "bastion-user"
:private-key-path "key-path"
:strict-host-key-checking :no}))
(ssh/forward-local-port session
3306
3306
"remote-mysql-host")
but even though I see no errors anywhere (and the port 3306 is open checking with nmap), I can't connect to the remote MySQL, while it works perfectly well with the ssh -L
command. Any idea what I'm doing wrong or how to get more debugging information?
Getting a CompilerException java.lang.ClassNotFoundException: clj-ssh.agent, compiling:(NO_SOURCE_PATH:1:1).
I am running from REPL, started using lein repl. clj-ssh is in my lein profile and ssh is resolved correctly (it fails authentication but I guess that is another issue)
This should probably default to ~/.ssh/known_hosts
.
Very occasionally, for reasons I don't understand (maybe TCP close?), a session disconnects between two calls to ssh/invoke
. Works for one command, and a few ms later, another command throws:
[2016/08/04 13:37:05.617] Caused by: com.jcraft.jsch.JSchException: Packet corrupt
[2016/08/04 13:37:05.617] at com.jcraft.jsch.Session.start_discard(Session.java:1059)
[2016/08/04 13:37:05.617] at com.jcraft.jsch.Session.read(Session.java:929)
[2016/08/04 13:37:05.617] at com.jcraft.jsch.Session.connect(Session.java:309)
[2016/08/04 13:37:05.617] at com.jcraft.jsch.Session.connect(Session.java:183)
[2016/08/04 13:37:05.617] at clj_ssh.ssh$fn__3689.invoke(ssh.clj:118)
[2016/08/04 13:37:05.617] at clj_ssh.ssh.protocols$fn__3647$G__3614__3656.invoke(protocols.clj:4)
[2016/08/04 13:37:05.617] at clj_ssh.ssh$connect.invoke(ssh.clj:401)
[2016/08/04 13:37:05.617] at clj_ssh.ssh$ssh.invoke(ssh.clj:721)
This occurs when invoke
checks whether the session is connected?
prior to executing the command. If not, clj-ssh attempts to connect the session again. However, reconnecting closed sessions is illegal, which causes the jsch state machine to explode with "packet corrupt". I thiiink I can work around this by dropping the session and creating a new one in my clj-ssh wrapper, but it's not obvious to me how we can do the same in clj-ssh directly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.