Skip to content

Commit cd44412

Browse files
committed
Merge branch 'release/0.4.0'
2 parents 78ac393 + 8a95260 commit cd44412

File tree

14 files changed

+1326
-1124
lines changed

14 files changed

+1326
-1124
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: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,87 @@
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
98

10-
(use 'clj-ssh.ssh)
9+
The `clj-ssh.cli` namespace provides some functions for ease of use at the REPL.
1110

12-
There is a simple `ssh` function, which by default, will try and use a id_rsa
13-
key in your $HOME/.ssh directory.
14-
15-
(ssh "hostname" "ls")
16-
17-
Strict host key checking can be turned off.
11+
```clj
12+
(use 'clj-ssh.cli)
13+
```
1814

19-
(default-session-options {:strict-host-key-checking :no})
15+
Use `ssh` to execute a command, say `ls`, on a remote host "my-host",
2016

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.
17+
```clj
18+
(ssh "my-host" "ls")
19+
=> {:exit 0 :out "file1\nfile2\n" :err "")
20+
```
2521

26-
More advance usage is possible.
22+
By default this will use the system ssh-agent to obtain your ssh keys, and it
23+
uses your current username, but this can be specified:
2724

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))))))
25+
```clj
26+
(ssh "my-host" "ls" :username "remote-user")
27+
=> {:exit 0 :out "file1\nfile2\n" :err "")
28+
```
3629

37-
SFTP is supported, both with a simple interface,
30+
Strict host key checking can be turned off:
3831

39-
(sftp "hostname" :put "/from/this/path" "to/this/path")
32+
```clj
33+
(default-session-options {:strict-host-key-checking :no})
34+
```
4035

41-
as well as more advanced usage.
36+
SFTP is also supported. For example, to copy a local file to a remote host
37+
"my-host":
4238

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"))))))
39+
```clj
40+
(sftp "my-host" :put "/from/this/path" "to/this/path")
41+
```
5042

5143
Note that any sftp commands that change the state of the sftp session (such as
5244
cd) do not work with the simplified interface, as a new session is created each
5345
time.
5446

47+
If your key has a passphrase, you will need to explicitly add your key either to
48+
the system's ssh-agent, or to clj-ssh's ssh-agent with the appropriate
49+
`add-identity` call.
50+
51+
### Non REPL
52+
53+
The `clj-ssh.ssh` namespace should be using SSH from functional code.
54+
55+
```clj
56+
(let [agent (ssh-agent {:use-system-ssh-agent false})]
57+
(add-identity agent "/user/name/.ssh/id_rsa")
58+
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
59+
(with-connection session
60+
(let [result (ssh session {:in "echo hello"})]
61+
(println (result :out)))
62+
(let [result (ssh session {:cmd "ls"}]
63+
(println (second result))))))
64+
```
65+
66+
The above example shows using `:in` to pass commands to a shell, and using
67+
`:cmd` to exec a command without a shell. When using `:cmd` you can still pass
68+
a stream or a string to `:in` to be used as the process' standard input.
69+
70+
```clj
71+
(let [agent (ssh-agent {})]
72+
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
73+
(with-connection session
74+
(let [channel (ssh-sftp session)]
75+
(with-channel-connection channel
76+
(sftp channel :cd "/remote/path")
77+
(sftp channel :put "/some/file" "filename"))))))
78+
```
79+
5580
SSH tunneling is also supported:
5681

5782
```clj
58-
(with-ssh-agent []
59-
(let [session (session "localhost" :strict-host-key-checking :no)]
83+
(let [agent (ssh-agent {:use-system-ssh-agent false})]
84+
(let [session (session agent "localhost" :strict-host-key-checking :no)]
6085
(with-connection session
6186
(with-local-port-forward [session 8080 80]
6287
(comment do something with port 8080 here)))))
@@ -69,11 +94,9 @@ SSH tunneling is also supported:
6994

7095
## FAQ
7196

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?
97+
Q: What does
98+
"4: Failure @ com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2289)"
99+
during an sftp transfer signify?
77100

78101
A: Probably a disk full, or permission error.
79102

@@ -82,7 +105,7 @@ A: Probably a disk full, or permission error.
82105
Via [clojars](http://clojars.org) and
83106
[Leiningen](http://github.com/technomancy/leiningen).
84107

85-
:dependencies [clj-ssh "0.3.3"]
108+
:dependencies [clj-ssh "0.4.0"]
86109

87110
or your favourite maven repository aware tool.
88111

ReleaseNotes.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Release Notes
22

3-
Current release is 0.3.3
3+
Current release is 0.4.0
4+
5+
## 0.4.0
6+
7+
- Split out clj-ssh.cli
8+
9+
clj-ssh.ssh is designed for composability and programmatic use. It takes
10+
map arguments for options and is fully functional.
11+
12+
clj-ssh.cli is intended to simplify repl usage. It takes variadic
13+
arguments for options and uses dynamic vars to provide defaults.
414

515
## 0.3.3
616

pom.xml

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

project.clj

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
(defproject clj-ssh "0.3.2-SNAPSHOT"
1+
(defproject clj-ssh "0.4.0"
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+
:exclusions [com.jcraft/jsch-agent-proxy]]
9+
[slingshot "0.10.2"]
10+
[com.jcraft/jsch "0.1.48"]]
11+
:dev-dependencies [[org.slf4j/slf4j-api "1.6.1"]
12+
[ch.qos.logback/logback-core "1.0.0"]
13+
[ch.qos.logback/logback-classic "1.0.0"]]
14+
:profiles {:dev {:dependencies [[org.slf4j/slf4j-api "1.6.1"]
15+
[ch.qos.logback/logback-core "1.0.0"]
16+
[ch.qos.logback/logback-classic "1.0.0"]
17+
[codox-md "0.1.0"]]}}
818
:multi-deps {"slingshot-0.10.1" [[slingshot "0.10.1"]
919
[org.clojure/clojure "1.2.1"]]
1020
"clojure-1.2.1" [[slingshot "0.10.1"]
@@ -14,5 +24,8 @@
1424
"clojure-1.4.0" [[slingshot "0.10.1"]
1525
[org.clojure/clojure "1.4.0-beta1"]]}
1626
:codox {:writer codox-md.writer/write-docs
17-
:version "0.3"
18-
:output-dir "doc/api/0.3"})
27+
:version "0.4"
28+
:output-dir "doc/api/0.4"
29+
:exclude [clj-ssh.agent clj-ssh.reflect clj-ssh.keychain]}
30+
:license {:name "Eclipse Public License"
31+
:url "http://www.eclipse.org/legal/epl-v10.html"})

0 commit comments

Comments
 (0)