func SpawnSSH(c *ConfSSH) error {
	if c.PrivateKey == "" {
		return fmt.Errorf("no host key has been set")
	}
	pk, err := ssh.ParsePrivateKey([]byte(c.PrivateKey))
	if err != nil {
		return fmt.Errorf("failed to parse private key")
	}
	c.ServerConfig.AddHostKey(pk)
	c.ServerConfig.PasswordCallback = getSSHHandlePassword(c)
	c.ServerConfig.PublicKeyCallback = getSSHHandlePublic(c)
	listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", c.BindHost, c.BindPort))
	if err != nil {
		return fmt.Errorf("failed to listen on %s:%d (%s)", c.BindHost, c.BindPort, err)
	}
	c.listener = listener
	go sshStart(c)
	return nil
}
SpawnSSH starts a logging SSH server
package flamingo
import (
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"encoding/pem"
	"fmt"
	"net"
	"strings"
	"sync"
	log "github.com/sirupsen/logrus"
	"golang.org/x/crypto/ssh"
)
type ConfSSH struct {
	PrivateKey   string
	BindPort     uint16
	BindHost     string
	RecordWriter *RecordWriter
	ServerConfig *ssh.ServerConfig
	shutdown     bool
	listener     net.Listener
	m            sync.Mutex
}
func (c *ConfSSH) IsShutdown() bool {
	c.m.Lock()
	defer c.m.Unlock()
	return c.shutdown
}
func (c *ConfSSH) Shutdown() {
	c.m.Lock()
	defer c.m.Unlock()
	c.shutdown = true
	c.listener.Close()
}
func NewConfSSH() *ConfSSH {
	return &ConfSSH{
		BindPort: 22,
		BindHost: "[::]",
		ServerConfig: &ssh.ServerConfig{
			ServerVersion: "SSH-2.0-OpenSSH_7.6p1",
		},
	}
}
func getSSHHandlePassword(c *ConfSSH) func(ssh.ConnMetadata, []byte) (*ssh.Permissions, error) {
	return func(sshConn ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
		c.RecordWriter.Record(
			"credential",
			"ssh",
			sshConn.RemoteAddr().String(),
			map[string]string{
				"username": sshConn.User(),
				"password": string(pass),
				"version":  string(sshConn.ClientVersion()),
				"method":   "password",
				"_server":  fmt.Sprintf("%s:%d", c.BindHost, c.BindPort),
			},
		)
		return nil, fmt.Errorf("password collected for %q", sshConn.User())
	}
}
func getSSHHandlePublic(c *ConfSSH) func(ssh.ConnMetadata, ssh.PublicKey) (*ssh.Permissions, error) {
	return func(sshConn ssh.ConnMetadata, pubkey ssh.PublicKey) (*ssh.Permissions, error) {
		c.RecordWriter.Record(
			"credential",
			"ssh",
			sshConn.RemoteAddr().String(),
			map[string]string{
				"username":      sshConn.User(),
				"pubkey-sha256": ssh.FingerprintSHA256(pubkey),
				"pubkey":        strings.TrimSpace(string(ssh.MarshalAuthorizedKey(pubkey))),
				"version":       string(sshConn.ClientVersion()),
				"method":        "pubkey",
				"_server":       fmt.Sprintf("%s:%d", c.BindHost, c.BindPort),
			},
		)
		return nil, fmt.Errorf("pubkey collected for %q", sshConn.User())
	}
}