// NewClient instantiates a new SSH Client object.
// N.B.: provide either the key (privateKey) or its path (privateKeyPath).
NewClient instantiates a new SSH Client object.
N.B.: provide either the key (privateKey) or its path (privateKeyPath).
// NewClient instantiates a new SSH Client object . // N . B . : provide either the key ( privateKey ) or its path ( privateKeyPath ) .
func NewClient(params ClientParams) (*Client, error) {
	log.WithFields(log.Fields{"user": params.User, "host": params.Host, "port": params.Port, "privateKeyPath": params.PrivateKeyPath, "printOutputs": params.PrintOutputs}).Debugf("creating SSH client")
	signer, err := sshutil.SignerFromPrivateKey(params.PrivateKeyPath, params.PrivateKey)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to read private key from \"%s\"", params.PrivateKeyPath)
	}
	hostPublicKey, err := sshutil.HostPublicKey(params.Host)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to read host %s's public key", params.Host)
	}
	config := &ssh.ClientConfig{
		User: params.User,
		Auth: []ssh.AuthMethod{
			ssh.PublicKeys(signer),
		},
		HostKeyCallback: sshutil.HostKeyCallback(hostPublicKey),
	}
	hostPort := fmt.Sprintf("%s:%d", params.Host, params.Port)
	client, err := ssh.Dial(tcp, hostPort, config)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to connect to %s", hostPort)
	}
	return &Client{
		client:       client,
		printOutputs: params.PrintOutputs,
	}, nil
}
func NewClient ( params ClientParams ) ( * Client , error ) { log . WithFields ( log . Fields { " " : params . User , " " : params . Host , " " : params . Port , " " : params . PrivateKeyPath , " " : params . PrintOutputs } ) . Debugf ( " " ) signer , err := sshutil . SignerFromPrivateKey ( params . PrivateKeyPath , params . PrivateKey ) if err != nil { return nil , errors . Wrapf ( err , " \" \" " , params . PrivateKeyPath ) } hostPublicKey , err := sshutil . HostPublicKey ( params . Host ) if err != nil { return nil , errors . Wrapf ( err , " " , params . Host ) } config := & ssh . ClientConfig { User : params . User , Auth : [ ] ssh . AuthMethod { ssh . PublicKeys ( signer ) , } , HostKeyCallback : sshutil . HostKeyCallback ( hostPublicKey ) , } hostPort := fmt . Sprintf ( " " , params . Host , params . Port ) client , err := ssh . Dial ( tcp , hostPort , config ) if err != nil { return nil , errors . Wrapf ( err , " " , hostPort ) } return & Client { client : client , printOutputs : params . PrintOutputs , } , nil }
NewClient instantiates a new SSH Client object.
NewClient instantiates a new SSH Client object .