An implementation of the OpenSSH ControlMaster protocol for Golang
NOTE: this relies on a fork of golang.org/x/crypto/ssh with support for custom transports (github.com/bored-engineer/ssh)
package main
import (
"log"
"github.com/bored-engineer/controlmaster"
)
func main() {
client, err := controlmaster.Dial("unix", "PATH_TO_CONTROLMASTER")
if err != nil {
log.Fatal(err)
}
session, err := client.NewSession()
if err != nil {
log.Fatal(err)
}
defer session.Close()
out, err := session.CombinedOutput("id")
if err != nil {
log.Fatal(err)
}
log.Println(string(out))
}