Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns ssh-repl.client
(:require [ :as io]))
(defn connect
([user host repl-port {:as options
:keys [ssh-port repl-host key password]
:or {ssh-port 22
repl-host "localhost"}}]
(let [client (doto (org.apache.sshd.client.SshClient/setUpDefaultClient) .start)
session (-> client (.connect user host ssh-port) (doto .await) .getSession)]
(if key
(.addPublicKeyIdentity session
"shhhh" (io/input-stream key)
(reify org.apache.sshd.common.config.keys.FilePasswordProvider
(getPassword [_ _] password))))
(.addPasswordIdentity session password))
(-> session .auth .verify)
{:ssh-session session
(fn []
(let [channel (.createDirectTcpipChannel session
( "ssh-repl-client" 0)
( repl-host repl-port))]
(-> channel .open .verify)
{:in (-> channel .getInvertedIn (io/writer :encoding "UTF-8"))
:out (-> channel .getInvertedOut (io/reader :encoding "UTF-8"))}))})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment