ssh

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ssh provides users with a simple interface for remote execution over SSH. While this package is for Efs2 it could easily be imported and used by others.

// Read a Key File
key, err := ssh.ReadKeyFile("~/.ssh/id_rsa", "aPass")
if err != nil {
  // do something
}

// Dial the remote host
conn, err := ssh.Dial(ssh.Config{
  Host: "example.com:22",
  User: "example",
  Key:  key,
})
if err != nil {
  // do something
}

// Upload a File
err = conn.Put(ssh.File{...})
if err != nil {
  // do something
}

// Run a Command
output, err := conn.Run(ssh.Command{...})
if err != nil {
  // do something
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// Cmd is the single line shell command for execution.
	Cmd string
}

Command is a structure that holds details for individual commands that execute remotely.

type Config

type Config struct {
	// Host contains the remote SSH host address in a hostname:port format. If no port is specified, the Dial function will return an error.
	Host string

	// User contains the remote host's username to use for authentication and must not be left blank.
	User string

	// Key provides an SSH key to use for authentication. This key is the private key and requires the public key to be pre-pushed to the remote host for authentication to work.
	Key ssh.Signer

	// Password provides a password to use for authentication. If the password is present, the Dial function will ignore the SSH Key authentication settings.
	Password string
}

Config provides SSH client configuration details to the Dial function. This configuration offers items such as hostname, port, username, and SSH Keys to use for authentication.

func ReadKeyFile

func ReadKeyFile(file string, pass []byte) (Config, error)

ReadKeyFile will open and load the SSH key from the provided file. If included, the password will allow this function to decrypt SSH keys.

type Conn

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

Conn is an SSH connection the internally holds both an SSH and SFTP session.

func Dial

func Dial(c Config) (*Conn, error)

Dial will open an SSH connection to the configured remote host. The returned connection can then upload files or execute commands.

func (*Conn) Close

func (c *Conn) Close()

Close will close the open SSH connection cleaning up any lingering executions.

func (*Conn) Put

func (c *Conn) Put(f File) error

Put will upload the specified file with the provided destination path and permissions. Currently, this function does not support directories. Each execution is a single file.

func (*Conn) Run

func (c *Conn) Run(t Command) ([]byte, error)

Run will execute the specified file returning both standard output and standard error as a combined value. Any error in execution will return an error, even if the command is partially successful.

type File

type File struct {
	// Source is the full path to the source file to be uploaded.
	Source string

	// Destination is the full path location of the destination filename.
	Destination string

	// Mode is the file permissions to be set upon upload.
	Mode os.FileMode
}

File is a structure that holds the details required for uploading files.

type Task

type Task struct {
	// Task is the original instruction used to create the task.
	Task string

	// Command is a command structure that provides command execution instructions.
	Command Command

	// File is a file structure that provides file upload instructions.
	File File
}

Task is a wrapper structure used during parsing of Efs2 files. Within this structure contains SSH command and file structures.

Jump to

Keyboard shortcuts

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