sshutil

package
v3.2.0-M2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadPrivateKey

func ReadPrivateKey(pk string) (ssh.AuthMethod, error)

ReadPrivateKey returns an authentication method relying on private/public key pairs The argument is : - either a path to the private key file, - or the content or this private key file

func ToPrivateKeyContent

func ToPrivateKeyContent(pk string) ([]byte, error)

ToPrivateKeyContent allows to convert private key content or file to byte array

Types

type Client

type Client interface {
	RunCommand(string) (string, error)
}

Client is interface allowing running command

type SSHAgent

type SSHAgent struct {
	Socket string
	// contains filtered or unexported fields
}

SSHAgent is an SSH agent

func NewSSHAgent

func NewSSHAgent(ctx context.Context) (*SSHAgent, error)

NewSSHAgent allows to return a new SSH Agent

func (*SSHAgent) AddKey

func (sa *SSHAgent) AddKey(privateKey string, lifeTime uint32) error

AddKey allows to add a key into ssh-agent keys list

func (*SSHAgent) GetAuthMethod

func (sa *SSHAgent) GetAuthMethod() ssh.AuthMethod

GetAuthMethod returns the auth method with all agent keys

func (*SSHAgent) RemoveAllKeys

func (sa *SSHAgent) RemoveAllKeys() error

RemoveAllKeys allows to remove all keys into ssh-agent keys list

func (*SSHAgent) RemoveKey

func (sa *SSHAgent) RemoveKey(privateKey string) error

RemoveKey allows to remove a key into ssh-agent keys list

func (*SSHAgent) Stop

func (sa *SSHAgent) Stop() error

Stop allows to cleanup and stop ssh-agent process

type SSHClient

type SSHClient struct {
	Config *ssh.ClientConfig
	Host   string
	Port   int
}

SSHClient is a client SSH

func (*SSHClient) CopyFile

func (client *SSHClient) CopyFile(source io.Reader, remotePath, permissions string) error

CopyFile allows to copy a reader over SSH with defined remote path and specific permissions

func (*SSHClient) GetSessionWrapper

func (client *SSHClient) GetSessionWrapper() (*SSHSessionWrapper, error)

GetSessionWrapper allows to return a session wrapper in order to handle stdout/stderr for running long synchronous commands

func (*SSHClient) RunCommand

func (client *SSHClient) RunCommand(cmd string) (string, error)

RunCommand allows to run a specified command

type SSHSessionWrapper

type SSHSessionWrapper struct {
	Stdout io.Reader
	Stderr io.Reader
	// contains filtered or unexported fields
}

SSHSessionWrapper is a wrapper with a piped SSH session

func (*SSHSessionWrapper) Close

func (sw *SSHSessionWrapper) Close() error

Close closes the session

func (*SSHSessionWrapper) RequestPty

func (sw *SSHSessionWrapper) RequestPty(term string, h, w int, termmodes ssh.TerminalModes) error

RequestPty requests the association of a pty with the session on the remote host.

func (*SSHSessionWrapper) RunCommand

func (sw *SSHSessionWrapper) RunCommand(ctx context.Context, cmd string) error

RunCommand allows to run a specified command from a session wrapper in order to handle stdout/stderr during long synchronous commands

func (*SSHSessionWrapper) Start

func (sw *SSHSessionWrapper) Start(cmd string) error

Start runs cmd on the remote host. Typically, the remote server passes cmd to the shell for interpretation. A Session only accepts one call to Run, Start or Shell.

func (*SSHSessionWrapper) StdinPipe

func (sw *SSHSessionWrapper) StdinPipe() (io.WriteCloser, error)

StdinPipe returns a pipe that will be connected to the remote command's standard input when the command starts.

Jump to

Keyboard shortcuts

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