@@ -50,23 +50,51 @@ the system's ssh-agent, or to clj-ssh's ssh-agent with the appropriate
50
50
51
51
### Non REPL
52
52
53
- The `clj-ssh.ssh` namespace should be using SSH from functional code.
53
+ The `clj-ssh.ssh` namespace should be used for SSH from functional code.
54
54
55
55
```clj
56
- (let [agent (ssh-agent {:use-system-ssh-agent false })]
57
- (add-identity agent " /user/name/.ssh/id_rsa" )
56
+ (let [agent (ssh-agent {})]
58
57
(let [session (session agent " localhost" {:strict-host-key-checking :no })]
59
58
(with-connection session
60
59
(let [result (ssh session {:in " echo hello" })]
61
60
(println (result :out )))
62
61
(let [result (ssh session {:cmd " ls" }]
63
- (println (second result))))))
62
+ (println (second result)))))))
64
63
```
65
64
66
65
The above example shows using `:in` to pass commands to a shell, and using
67
66
`:cmd` to exec a command without a shell. When using `:cmd` you can still pass
68
67
a stream or a string to `:in` to be used as the process' standard input.
69
68
69
+ By default, the system ssh-agent is used, which means the ssh keys you use at
70
+ the command line level should automatically be picked up (this should also work
71
+ with `pageant` on windows).
72
+
73
+ You can forward the ssh-agent, which allows you to run ssh based commands on the
74
+ remote host using the credentials in your local ssh-agent:
75
+
76
+ ```clj
77
+ (let [agent (ssh-agent {})]
78
+ (let [session (session agent " localhost" {:strict-host-key-checking :no })]
79
+ (with-connection session
80
+ (let [result (ssh session {:in " ssh somehost ls" :agent-forwarding true })]
81
+ (println (result :out ))))))
82
+ ```
83
+
84
+ If you prefer not to use the system ssh-agent, or one is not running on your
85
+ system, then a local, isolated ssh-agent can be used.
86
+
87
+ ```clj
88
+ (let [agent (ssh-agent {:use-system-ssh-agent false })]
89
+ (add-identity agent " /user/name/.ssh/id_rsa" )
90
+ (let [session (session agent " localhost" {:strict-host-key-checking :no })]
91
+ (with-connection session
92
+ (let [result (ssh session {:in " echo hello" })]
93
+ (println (result :out )))))
94
+ ```
95
+
96
+ SFTP is supported:
97
+
70
98
```clj
71
99
(let [agent (ssh-agent {})]
72
100
(let [session (session agent " localhost" {:strict-host-key-checking :no })]
@@ -80,7 +108,7 @@ a stream or a string to `:in` to be used as the process' standard input.
80
108
SSH tunneling is also supported:
81
109
82
110
```clj
83
- (let [agent (ssh-agent {:use-system-ssh-agent false })]
111
+ (let [agent (ssh-agent {})]
84
112
(let [session (session agent " localhost" {:strict-host-key-checking :no })]
85
113
(with-connection session
86
114
(with-local-port-forward [session 8080 80 ]
0 commit comments