clj-ssh icon indicating copy to clipboard operation
clj-ssh copied to clipboard

non system agent not working?

Open joachimdb opened this issue 10 years ago • 3 comments

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)

joachimdb avatar Jun 18 '14 12:06 joachimdb

The other difference in your two cases is :strict-host-key-checking, and I'm not sure using the non system agent supports :known-hosts-path.

hugoduncan avatar Jun 18 '14 15:06 hugoduncan

Thanks for the reply Hugo, but I don't get why you say that both cases differ in :strict-host-key-checking, they both set it to :no? Furthermore, the ssh-agent function does take a :known-hosts-path, setting it to "~/.ssh/known_hosts" by default when not provided, irrespective of whether a system-agent is used or not?

Anyway, I can't get the non-system ssh-agent to work, not even when leaving out the strict-host-key-checking and/or the :known-hosts-path. Any ideas?

joachimdb avatar Jun 19 '14 14:06 joachimdb

JSchException USERAUTH fail typically means the password is incorrect. Does your key have a password? It might make sense that the version of your code using the system ssh-agent works since it can provide the key without prompting the user for the password.

peterhhchan avatar Aug 28 '19 05:08 peterhhchan