Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clj-ssh should work when known_hosts file is absent. #58

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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=
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-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
(let [result (ssh session {:in "echo hello"})]
(println (result :out)))))
```


SFTP is supported:

Expand Down
4 changes: 2 additions & 2 deletions src/clj_ssh/ssh.clj
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@

(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")}}]
(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))
Expand Down