ssh

package
v0.0.0-...-6bb069b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2022 License: GPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const SSH_AWS = "/go/src/weibo.com/opendcp/jupiter/conf/zhaowei9.pem"

Variables

View Source
var (
	ErrKeyGeneration     = errors.New("Unable to generate key")
	ErrValidation        = errors.New("Unable to validate key")
	ErrPublicKey         = errors.New("Unable to convert public key")
	ErrUnableToWriteFile = errors.New("Unable to write file")
)

Functions

func GenSSHKey

func GenSSHKey(path string) error

func GetSSHKeyFromDb

func GetSSHKeyFromDb(mac *models.Instance, path string, isPriv bool) error

func NewConfig

func NewConfig(user string, auth *Auth) (*ssh.ClientConfig, error)

Types

type Auth

type Auth struct {
	Passwords []string
	Keys      []string
}

type Client

type Client struct {
	Config   *ssh.ClientConfig
	Hostname string
	Port     int
}

func NewClient

func NewClient(user string, host string, port int, auth *Auth) (*Client, error)

func (*Client) DisPassLogin

func (sshCli *Client) DisPassLogin() error

Disable ssh passowrd login

func (*Client) GenerateSSHKey

func (sshCli *Client) GenerateSSHKey(instanceId string, path string) error

Generate SSH keypair based on path of the private key The public key would be generated to the same path with ".pub" added

func (*Client) Run

func (client *Client) Run(command string) (Output, error)

func (*Client) RunWithAttempt

func (client *Client) RunWithAttempt(command string, maxAttempt int) (Output, error)

func (*Client) StoreSSHKey

func (sshCli *Client) StoreSSHKey(instanceId string) error

type KeyPair

type KeyPair struct {
	PrivateKey []byte
	PublicKey  []byte
}

func NewKeyPair

func NewKeyPair() (keyPair *KeyPair, err error)

Generate a new SSH keypair This will return a private & public key encoded as DER.

func (*KeyPair) Fingerprint

func (kp *KeyPair) Fingerprint() string

Calculate the fingerprint of the public key

func (*KeyPair) StoreDb

func (kp *KeyPair) StoreDb(instanceId string) error

func (*KeyPair) UploadKey

func (kp *KeyPair) UploadKey(sshCli *Client) error

func (*KeyPair) WriteToFile

func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) error

Write keypair to files

type Output

type Output struct {
	Stdout io.Reader
	Stderr io.Reader
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL