modulepackage
0.0.0-20191008104859-6690589472d4
Repository: https://github.com/0xef53/go-sshpool.git
Documentation: pkg.go.dev
# README
go-sshpool
Package sshpool
provides an SSH connection pool implementation for the Go language.
Installation
go get github.com/0xef53/go-sshpool
Example
agentSocket, ok := os.LookupEnv("SSH_AUTH_SOCK")
if !ok {
log.Fatalln("Could not connect to SSH_AUTH_SOCK. Is ssh-agent running?")
}
poolCfg := &sshpool.PoolConfig{
GCInterval: 5 * time.Second,
MaxConns: 5,
}
p := sshpool.NewPool(poolCfg)
sshCfg := &sshpool.SSHConfig{
User: "root",
Host: "localhost",
Port: 22,
AgentSocket: agentSocket,
Timeout: 30 * time.Second,
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
output, err := p.CombinedOutput(sshCfg, "uname -a ; sleep 3", nil, nil)
if err != nil {
log.Fatalf("%s: %s\n", err, output)
}
fmt.Println(string(output))
fmt.Println("Active connections:", p.ActiveConns())
Documentation
Use Godoc documentation for reference and usage.
# Functions
NewPool creates a new pool of connections and starts GC.
NewSSHConn creates and configures new SSH connection according to the given SSH config.
# Structs
PoolConfig defines configuration options of the pool.
SSHConn defines the configuration options of the SSH connection.
SSHConn is a wrapper around the standard ssh.Client which implements some additional parameters required for the connection pool work properly.
Pool maintains a pool of SSH connections and sessions.