ssh

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSSHPort is the standard SSH port
	DefaultSSHPort = 22

	// DefaultConnectTimeout is the default timeout for SSH connection establishment
	DefaultConnectTimeout = 30 * time.Second
)

SSH connection defaults

View Source
const (
	// DirPermissionsSSH is the permission mode for .ssh directory (rwx------)
	DirPermissionsSSH = 0700

	// FilePermissionsKnownHosts is the permission mode for known_hosts file (rw-------)
	FilePermissionsKnownHosts = 0600

	// FilePermissionsPrivateKey is the permission mode for SSH private keys (rw-------)
	FilePermissionsPrivateKey = 0600
)

File and directory permissions for SSH-related files

Variables

This section is empty.

Functions

func Quote

func Quote(s string) string

Quote returns s wrapped so it is safe to interpolate as a single argument into a POSIX shell command line executed on the remote server.

Remote commands in shippy are built with fmt.Sprintf and run through the remote login shell (session.Run / CombinedOutput). Any value that is not a trusted literal — file paths derived from local filenames, deploy paths, shared entries, extracted database names, etc. — MUST be passed through Quote first, otherwise shell metacharacters in that value lead to command injection (CWE-78) on the deploy target.

The value is wrapped in single quotes, within which the shell treats every character literally. The only character that cannot appear inside single quotes is the single quote itself, so each embedded single quote is replaced by the standard close-quote, backslash-escaped-quote, reopen-quote sequence (see the ReplaceAll below).

Types

type Client

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

Client represents an SSH client connection

func NewClient

func NewClient(host, user, keyPath string) (*Client, error)

NewClient creates a new SSH client

func NewClientWithOptions

func NewClientWithOptions(opts ClientOptions) (*Client, error)

NewClientWithOptions creates a new SSH client with full options

func (*Client) Close

func (c *Client) Close() error

Close closes the SSH connection

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes the SSH connection

func (*Client) Dial

func (c *Client) Dial(network, addr string) (net.Conn, error)

Dial opens a connection to addr from the remote host. Used for SSH tunneling (e.g., connecting to a remote database).

func (*Client) MkdirAll

func (c *Client) MkdirAll(path string) error

MkdirAll creates a directory and all parent directories on the remote server

func (*Client) RsyncSender added in v0.2.0

func (c *Client) RsyncSender(remoteCmd string, run func(io.ReadWriteCloser) error) error

RsyncSender starts remoteCmd (a remote `rsync --server ...` receiver) over the SSH connection and hands run an io.ReadWriteCloser wired to the command's stdin+stdout, so a local rsync client can speak the rsync protocol to the real remote rsync. Stderr from the remote rsync is captured and surfaced on failure.

func (*Client) RunCommand

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

RunCommand executes a command on the remote server

func (*Client) RunCommandWithOutput

func (c *Client) RunCommandWithOutput(cmd string, stdout, stderr io.Writer) error

RunCommandWithOutput executes a command and streams output to stdout/stderr

func (*Client) UploadFile

func (c *Client) UploadFile(localPath, remotePath string, mode os.FileMode) error

UploadFile uploads a file to the remote server

type ClientOptions

type ClientOptions struct {
	Host               string
	Port               int
	User               string
	KeyPath            string
	SSHOptions         map[string]string
	SSHMultiplexing    bool
	KnownHostsFile     string
	HostKeyFingerprint string
	ProxyCommand       string // optional: shell command to establish TCP transport (e.g. "/usr/bin/nc %h %p")
}

ClientOptions represents SSH client configuration options

type Command

type Command struct {
	Name string
	Run  string

	// Context, when non-empty, is a subcontext-entry prefix (e.g.
	// "docker exec php85"). The command — including the `cd` into the release
	// directory — is wrapped as `<Context> sh -c '<cd workDir && Run>'` so it
	// runs inside that context. Empty means run directly on the remote host.
	Context string
}

Command represents a command to execute

type Executor

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

Executor handles command execution on remote servers

func NewExecutor

func NewExecutor(client *Client) *Executor

NewExecutor creates a new command executor

func (*Executor) Execute

func (e *Executor) Execute(commands []Command, workDir string) error

Execute runs a list of commands sequentially

Jump to

Keyboard shortcuts

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