Skip to content

Commit f64186f

Browse files
committed
Add some description of using the system ssh-agent
1 parent 0795a31 commit f64186f

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

README.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,51 @@ the system's ssh-agent, or to clj-ssh's ssh-agent with the appropriate
5050

5151
### Non REPL
5252

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.
5454

5555
```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 {})]
5857
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
5958
(with-connection session
6059
(let [result (ssh session {:in "echo hello"})]
6160
(println (result :out)))
6261
(let [result (ssh session {:cmd "ls"}]
63-
(println (second result))))))
62+
(println (second result)))))))
6463
```
6564

6665
The above example shows using `:in` to pass commands to a shell, and using
6766
`:cmd` to exec a command without a shell. When using `:cmd` you can still pass
6867
a stream or a string to `:in` to be used as the process' standard input.
6968

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+
7098
```clj
7199
(let [agent (ssh-agent {})]
72100
(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.
80108
SSH tunneling is also supported:
81109

82110
```clj
83-
(let [agent (ssh-agent {:use-system-ssh-agent false})]
111+
(let [agent (ssh-agent {})]
84112
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
85113
(with-connection session
86114
(with-local-port-forward [session 8080 80]

0 commit comments

Comments
 (0)