From db2ccac8acef210cf96d37009c9fd8c1d4c65159 Mon Sep 17 00:00:00 2001 From: Ravi Gorrepati Date: Wed, 20 Feb 2019 17:18:40 -0800 Subject: [PATCH 1/5] - Allow for not using the default known_hosts file when creating the ssh-agent. This is useful in cases where strict-host-key-checking is set to no and we don't have a known_hosts file in the usual location --- src/clj_ssh/ssh.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clj_ssh/ssh.clj b/src/clj_ssh/ssh.clj index d0ec38b..1c6b293 100644 --- a/src/clj_ssh/ssh.clj +++ b/src/clj_ssh/ssh.clj @@ -146,7 +146,7 @@ (let [agent (JSch.)] (when use-system-ssh-agent (agent/connect agent)) - (when known-hosts-path + (when-not (= :no-default-path known-hosts-path) (locking hosts-file (.setKnownHosts agent known-hosts-path))) agent)) From f67631b5e0bb8b96627c1489cef7d8627523436a Mon Sep 17 00:00:00 2001 From: Ravi Gorrepati Date: Wed, 20 Feb 2019 17:34:54 -0800 Subject: [PATCH 2/5] - Replaced occurrences of lein2 with lein --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 58f734a..9d4a201 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: clojure -lein: lein2 +lein: lein before_script: - ssh-keygen -N "" -f ~/.ssh/id_rsa - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys @@ -11,9 +11,9 @@ before_script: - echo "clj-ssh" > pp - chmod +x pp - setsid ssh-add ~/.ssh/clj_ssh_pp < pp -script: lein2 test +script: lein test after_success: -- lein2 pallet-release push +- lein pallet-release push env: global: secure: eOBqYhJhOJMtRiMKs9ZgG4pEHFy7YqiBZ5NUEWUYD6qav6sMRHqqR5F04NRI37SmnIupzeTChqfRgX0DOwHeTl4u+QJnwRDH2z3avu75FbtZWgiGrxzE39SESpVj/zsyDrEUzT7ZiMayXKyNa3ObiJ8vBUFT7x/OZyRp/1rJxHU= From 33a47a87c6a6d0ec821bb53325e4cb11912d3a07 Mon Sep 17 00:00:00 2001 From: Ravi Gorrepati Date: Wed, 20 Feb 2019 17:43:10 -0800 Subject: [PATCH 3/5] - Adding documentation on how to not use the default path for known_hosts file. --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index c950da8..15a6014 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,20 @@ system, then a local, isolated ssh-agent can be used. (let [result (ssh session {:in "echo hello"})] (println (result :out))))) ``` +If the known_hosts file is not in the default location, and you don't need to read it anyways, +because you turned off strict-host-key-checking, you can advise ssh-agent to not attempt to +read the known_hosts file + +```clj +(let [agent (ssh-agent {:use-system-ssh-agent false + :known-host-path :no-default-path})] + (add-identity agent {:private-key-path "/user/name/.ssh/id_rsa"}) + (let [session (session agent "host-ip" {:strict-host-key-checking :no})] + (with-connection session + (let [result (ssh session {:in "echo hello"})] + (println (result :out))))) +``` + SFTP is supported: From cf2bdd337e0a8a4e1fb416517d5c43352a5add4c Mon Sep 17 00:00:00 2001 From: Ravi Gorrepati Date: Wed, 20 Feb 2019 17:45:43 -0800 Subject: [PATCH 4/5] - Fixing doc. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15a6014..1c58113 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ read the known_hosts file ```clj (let [agent (ssh-agent {:use-system-ssh-agent false - :known-host-path :no-default-path})] + :known-hosts-path :no-default-path})] (add-identity agent {:private-key-path "/user/name/.ssh/id_rsa"}) (let [session (session agent "host-ip" {:strict-host-key-checking :no})] (with-connection session From d3d7ea2493937b6890c04edf0e99d7b6497de372 Mon Sep 17 00:00:00 2001 From: Ravi Gorrepati Date: Wed, 20 Feb 2019 18:09:27 -0800 Subject: [PATCH 5/5] - Removing the type annotation on known-hosts-path as it can be a keyword now. --- src/clj_ssh/ssh.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clj_ssh/ssh.clj b/src/clj_ssh/ssh.clj index 1c6b293..983c04d 100644 --- a/src/clj_ssh/ssh.clj +++ b/src/clj_ssh/ssh.clj @@ -139,7 +139,7 @@ (defn ssh-agent "Create a ssh-agent. By default a system ssh-agent is preferred." - [{:keys [use-system-ssh-agent ^String known-hosts-path] + [{:keys [use-system-ssh-agent known-hosts-path] :or {use-system-ssh-agent true known-hosts-path (str (. System getProperty "user.home") "/.ssh/known_hosts")}}]