func (c *command) connect() error {
	if c.connected {
		return transport.ErrAlreadyConnected
	}
	if c.auth == nil {
		if err := c.setAuthFromEndpoint(); err != nil {
			return err
		}
	}
	var err error
	config, err := c.auth.ClientConfig()
	if err != nil {
		return err
	}
	overrideConfig(c.config, config)
	c.client, err = ssh.Dial("tcp", c.getHostWithPort(), config)
	if err != nil {
		return err
	}
	c.Session, err = c.client.NewSession()
	if err != nil {
		_ = c.client.Close()
		return err
	}
	c.connected = true
	return nil
}
connect connects to the SSH server, unless a AuthMethod was set with
SetAuth method, by default uses an auth method based on PublicKeysCallback,
it connects to a SSH agent, using the address stored in the SSH_AUTH_SOCK
environment var.
package ssh
import (
	"fmt"
	"reflect"
	"gopkg.in/src-d/go-git.v4/plumbing/transport"
	"gopkg.in/src-d/go-git.v4/plumbing/transport/internal/common"
	"golang.org/x/crypto/ssh"
)
var DefaultClient = NewClient(nil)
func NewClient(config *ssh.ClientConfig) transport.Transport {
	return common.NewClient(&runner{config: config})
}
var DefaultAuthBuilder = func(user string) (AuthMethod, error) {
	return NewSSHAgentAuth(user)
}
const DefaultPort = 22
type runner struct {
	config *ssh.ClientConfig
}
func (r *runner) Command(cmd string, ep *transport.Endpoint, auth transport.AuthMethod) (common.Command, error) {
	c := &command{command: cmd, endpoint: ep, config: r.config}
	if auth != nil {
		c.setAuth(auth)
	}
	if err := c.connect(); err != nil {
		return nil, err
	}
	return c, nil
}
type command struct {
	*ssh.Session
	connected bool
	command   string
	endpoint  *transport.Endpoint
	client    *ssh.Client
	auth      AuthMethod
	config    *ssh.ClientConfig
}
func (c *command) setAuth(auth transport.AuthMethod) error {
	a, ok := auth.(AuthMethod)
	if !ok {
		return transport.ErrInvalidAuthMethod
	}
	c.auth = a
	return nil
}
func (c *command) Start() error {
	return c.Session.Start(endpointToCommand(c.command, c.endpoint))
}
func (c *command) Close() error {
	if !c.connected {
		return nil
	}
	c.connected = false
	_ = c.Session.Close()
	return c.client.Close()
}