Skip to content

Commit d37b8e8

Browse files
committed
Merge branch 'feature/add-public-key-args' into develop
2 parents 87850f6 + e78c2db commit d37b8e8

File tree

13 files changed

+1283
-1118
lines changed

13 files changed

+1283
-1118
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ lib
55
classes
66
autodoc/**
77
doc/**
8+
.lein-deps-sum
9+
.lein-failures

README.md

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,69 @@
11
# clj-ssh
22

3-
SSH in clojure. Uses jsch. Provides a ssh function that tries to look similar
4-
to clojure.contrib.shell/sh.
3+
SSH in clojure. Uses jsch.
54

65
## Usage
76

8-
The top level namespace is `clj-ssh.ssh`
7+
### REPL
8+
9+
The `clj-ssh.cli` namespace provides some functions for ease of use at the REPL.
910

1011
(use 'clj-ssh.ssh)
1112

12-
There is a simple `ssh` function, which by default, will try and use a id_rsa
13-
key in your $HOME/.ssh directory.
13+
There is a simple `ssh` function, which by default, will use the system
14+
ssh-agent.
1415

1516
(ssh "hostname" "ls")
1617

1718
Strict host key checking can be turned off.
1819

1920
(default-session-options {:strict-host-key-checking :no})
2021

21-
By default, your current username and id_rsa key are used. If your key has a
22-
passphrase, and you are on OSX, then you should be asked for access to your
23-
keychain. If you are on any other OS, you will need to explicitly add your key
24-
to the clj-ssh's ssh-agent with the appropriate add-identity call.
22+
By default, your current username is used. If your key has a passphrase, and
23+
you are on OSX, then you should be asked for access to your keychain. If you
24+
are on any other OS without a ssh-agent, you will need to explicitly add your
25+
key to the clj-ssh's ssh-agent with the appropriate add-identity call.
2526

26-
More advance usage is possible.
27+
SFTP is supported:
2728

28-
(with-ssh-agent []
29-
(add-identity "/user/name/.ssh/id_dsa")
30-
(let [session (session "localhost" :strict-host-key-checking :no)]
31-
(with-connection session
32-
(let [result (ssh session :in "echo hello" :result-map true)]
33-
(println (result :out)))
34-
(let [result (ssh session "/bin/bash" "-c" "ls" "/")]
35-
(println (second result))))))
29+
```clj
30+
(sftp "hostname" :put "/from/this/path" "to/this/path")
31+
```
3632

37-
SFTP is supported, both with a simple interface,
33+
Note that any sftp commands that change the state of the sftp session (such as
34+
cd) do not work with the simplified interface, as a new session is created each
35+
time.
3836

39-
(sftp "hostname" :put "/from/this/path" "to/this/path")
37+
### Non REPL
4038

41-
as well as more advanced usage.
39+
The `clj-ssh.ssh` namespace should be using SSH from functional code.
4240

43-
(with-ssh-agent []
44-
(let [session (session "localhost" :strict-host-key-checking :no)]
45-
(with-connection session
46-
(let [channel (ssh-sftp session)]
47-
(with-connection channel
48-
(sftp channel :cd "/remote/path")
49-
(sftp channel :put "/some/file" "filename"))))))
41+
```clj
42+
(let [agent (ssh-agent {:use-system-ssh-agent false})]
43+
(add-identity agent "/user/name/.ssh/id_rsa")
44+
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
45+
(with-connection session
46+
(let [result (ssh session {:in "echo hello"})]
47+
(println (result :out)))
48+
(let [result (ssh session "/bin/bash" "-c" "ls" "/")]
49+
(println (second result))))))
50+
```
5051

51-
Note that any sftp commands that change the state of the sftp session (such as
52-
cd) do not work with the simplified interface, as a new session is created each
53-
time.
52+
```clj
53+
(let [agent (ssh-agent {})]
54+
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
55+
(with-connection session
56+
(let [channel (ssh-sftp session)]
57+
(with-channel-connection channel
58+
(sftp channel :cd "/remote/path")
59+
(sftp channel :put "/some/file" "filename"))))))
60+
```
5461

5562
SSH tunneling is also supported:
5663

5764
```clj
58-
(with-ssh-agent []
59-
(let [session (session "localhost" :strict-host-key-checking :no)]
65+
(let [agent (ssh-agent {:use-system-ssh-agent false})]
66+
(let [session (session agent "localhost" :strict-host-key-checking :no)]
6067
(with-connection session
6168
(with-local-port-forward [session 8080 80]
6269
(comment do something with port 8080 here)))))
@@ -69,11 +76,9 @@ SSH tunneling is also supported:
6976

7077
## FAQ
7178

72-
Q: Why doesn't clj-ssh integrate with the OS's ssh agent?
73-
74-
A: Java has no access to the Unix domain socket used by the system ssh-agent.
75-
76-
Q: What does "4: Failure @ com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2289)" during an sftp transfer signify?
79+
Q: What does
80+
"4: Failure @ com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2289)"
81+
during an sftp transfer signify?
7782

7883
A: Probably a disk full, or permission error.
7984

@@ -82,7 +87,7 @@ A: Probably a disk full, or permission error.
8287
Via [clojars](http://clojars.org) and
8388
[Leiningen](http://github.com/technomancy/leiningen).
8489

85-
:dependencies [clj-ssh "0.3.3"]
90+
:dependencies [clj-ssh "0.4.0-SNAPSHOT"]
8691

8792
or your favourite maven repository aware tool.
8893

pom.xml

Lines changed: 0 additions & 185 deletions
This file was deleted.

project.clj

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
(defproject clj-ssh "0.3.2-SNAPSHOT"
1+
(defproject clj-ssh "0.4.0-SNAPSHOT"
22
:description "Library for using SSH from clojure."
3-
:dependencies [[org.clojure/clojure "1.2.0"]
3+
:url "https://github.com/hugoduncan/clj-ssh"
4+
:dependencies [[org.clojure/clojure "1.2.1"]
45
[org.clojure/tools.logging "0.1.2"]
5-
[slingshot "0.2.0"]
6-
[com.jcraft/jsch "0.1.44-1"]]
7-
:dev-dependencies [[log4j/log4j "1.2.14"]]
6+
[jsch-agent-proxy "0.0.4"]
7+
[jsch-agent-proxy/jsch-agent-proxy-jna "0.0.4"]
8+
[slingshot "0.10.2"]
9+
[com.jcraft/jsch "0.1.48"]]
10+
:dev-dependencies [[org.slf4j/slf4j-api "1.6.1"]
11+
[ch.qos.logback/logback-core "1.0.0"]
12+
[ch.qos.logback/logback-classic "1.0.0"]]
13+
:profiles {:dev {:dependencies [[org.slf4j/slf4j-api "1.6.1"]
14+
[ch.qos.logback/logback-core "1.0.0"]
15+
[ch.qos.logback/logback-classic "1.0.0"]
16+
[codox-md "0.1.0"]]}}
817
:multi-deps {"slingshot-0.10.1" [[slingshot "0.10.1"]
918
[org.clojure/clojure "1.2.1"]]
1019
"clojure-1.2.1" [[slingshot "0.10.1"]
@@ -14,5 +23,8 @@
1423
"clojure-1.4.0" [[slingshot "0.10.1"]
1524
[org.clojure/clojure "1.4.0-beta1"]]}
1625
:codox {:writer codox-md.writer/write-docs
17-
:version "0.3"
18-
:output-dir "doc/api/0.3"})
26+
:version "0.4"
27+
:output-dir "doc/api/0.4"
28+
:exclude [clj-ssh.agent clj-ssh.reflect clj-ssh.keychain]}
29+
:license {:name "Eclipse Public License"
30+
:url "http://www.eclipse.org/legal/epl-v10.html"})

0 commit comments

Comments
 (0)