ssh

package
v0.0.0-...-cd881a2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*ssh.Client
	// contains filtered or unexported fields
}

Client is a custom SSH client with extra utility methods.

func (*Client) Close

func (c *Client) Close() error

Close the client.

func (*Client) NewSession

func (c *Client) NewSession() (*Session, error)

NewSession creates a new Session. A session is used to run a command.

func (*Client) RunSimpleOutput

func (c *Client) RunSimpleOutput(cmd string) (string, error)

RunSimpleOutput runs cmd on the remote system. Stdout is returned as a string. On error, the stderr is contained in the returned error.

type Dialer

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

Dialer is responsible for creating new ssh connections with a given set of ssh options.

func NewDialer

func NewDialer(sshOptions SshOptions) (*Dialer, error)

NewDialer creates a new ssh dialer which will create ssh clients and tunnels based on the provided options.

func (*Dialer) Close

func (d *Dialer) Close() error

Closes the ssh dialer.

func (*Dialer) DefaultCommand

func (d *Dialer) DefaultCommand(ctx context.Context) *exec.Cmd

DefaultCommand returns a SSH command with default flags set.

func (*Dialer) DialWithSystemSSH

func (d *Dialer) DialWithSystemSSH(ctx context.Context, destination string) (*Client, error)

DialWithSystemSSH connects to destination and return a Client. Affected by ssh_config(5).

It uses the ssh command on the system, which understands user SSH configuration (~/.ssh/config) to make the initial connection. A tunnel: a UNIX domain socket is then set to forward traffic to port 22 on the destination system. Then the Client is created, by connecting to the UNIX domain socket. The benefit of doing so is to avoid the need of parsing ssh configuration, while still having a programmatic API, instead of having to deal with ssh child processes.

type KeyChain

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

func NewKeyChain

func NewKeyChain() (*KeyChain, error)

NewKeyChain creates a KeyChain holding bundled SSH keys.

KeyChain.Delete() must be called to clean up resources.

func (*KeyChain) Delete

func (kc *KeyChain) Delete() error

Delete cleans up the key chain

func (*KeyChain) SSHAuthMethod

func (kc *KeyChain) SSHAuthMethod() ssh.AuthMethod

SSHAuthMethod returns a ssh.AuthMethod using the keys in the KeyChain.

func (*KeyChain) SSHCommandOptions

func (kc *KeyChain) SSHCommandOptions() []string

SSHCommandOptions returns ssh command line options that uses the keys.

type Session

type Session struct {
	*ssh.Session
}

func (*Session) SimpleOutput

func (s *Session) SimpleOutput(cmd string) (string, error)

SimpleOutput runs cmd on the remote system. Stdout is returned as a string. On error, the stderr is contained in the returned error.

type SshOptions

type SshOptions struct {
	Port string
}

SshOptions is the set of all supported ssh options.

type Tunnel

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

Tunnel is a UNIX domain socket forwarded to a remote by the system's SSH command. Tunnel is used to allow x/crypto/ssh to connect to SSH servers with complex configs.

func (*Tunnel) Close

func (t *Tunnel) Close() error

Close the tunnel.

func (*Tunnel) SSHServerSocket

func (t *Tunnel) SSHServerSocket() string

SSHServerSocket returns the path of the UNIX domain socket that forwards to the remote host's TCP port 22.

Jump to

Keyboard shortcuts

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