ssh

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package ssh allows to manage SSH connections and send commands through them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(closeable Closeable, ignoreErrors ...string) error

Close closes a Closeable.

func NoOpHostKeyCallback

func NoOpHostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error

NoOpHostKeyCallback is an ssh.HostKeyCallback that does nothing. Only use this when you're sure you don't want to check the host key at all (e.g., only for testing and non-production use cases).

func RunCommandAndGetOutput

func RunCommandAndGetOutput(host Host, cmd string) (string, error)

RunCommandAndGetOutput will run the given command on the host over SSH and return the combined (stdout + stderr) output.

func RunCommandAndGetStdout

func RunCommandAndGetStdout(host Host, cmd string) (string, error)

RunCommandAndGetStdout will run the given command on the host over SSH and return the stdout of the underlying command.

Types

type Closeable

type Closeable interface {
	Close() error
}

Closeable can be closed.

type Host

type Host struct {
	Hostname    string // host name or ip address
	SSHUserName string // user name
	CustomPort  int    // port number to use to connect to the host (port 22 will be used if unset)

	JumpHost *Host // Another host to use as a jump host to reach this host.

	HostKeyCallback ssh.HostKeyCallback // Callback function for handling host key checks.

	// set one or more authentication methods,
	// the first valid method will be used
	PrivateKey       string    // ssh private key to use as authentication method (disabled by default)
	SSHAgent         bool      // enable authentication using your existing local SSH agent (disabled by default)
	OverrideSSHAgent *SSHAgent // enable an in process `SSHAgent` for connections to this host (disabled by default)
	Password         string    // plain text password (blank by default)
}

Host is a remote host.

type SSHAgent

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

SSHAgent represents an instance of the ssh-agent process.

func NewSSHAgent

func NewSSHAgent(logger *logrus.Entry, socketDir string, socketFile string) (*SSHAgent, error)

Create SSH agent, start it in background and returns control back to the main thread You should stop the agent to cleanup files afterwards by calling `defer s.Stop()`

func SSHAgentWithPrivateKey

func SSHAgentWithPrivateKey(logger *logrus.Entry, privateKey string) (*SSHAgent, error)

Instantiates and returns an in-memory ssh agent with the given private key already added You should stop the agent to cleanup files afterwards by calling `defer sshAgent.Stop()`

func SSHAgentWithPrivateKeys

func SSHAgentWithPrivateKeys(logger *logrus.Entry, privateKeys []string) (*SSHAgent, error)

Instantiates and returns an in-memory ssh agent with the given private key(s) already added You should stop the agent to cleanup files afterwards by calling `defer sshAgent.Stop()`

func (*SSHAgent) SocketFile

func (s *SSHAgent) SocketFile() string

expose socketFile variable

func (*SSHAgent) Stop

func (s *SSHAgent) Stop()

Stop and clean up SSH agent

Jump to

Keyboard shortcuts

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