Help us shape the future of Go! Take the 2026 Go Developer Survey

ssh

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MPL-2.0 Imports: 31 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MarkerStartPrefix = "# Devsy Start "
	MarkerEndPrefix   = "# Devsy End "
)
View Source
var (
	DevsySSHHostKeyFile    = "id_" + config.BinaryName + "_rsa_host"
	DevsySSHPrivateKeyFile = "id_" + config.BinaryName + "_rsa"
	DevsySSHPublicKeyFile  = "id_" + config.BinaryName + "_rsa.pub"
)
View Source
var ErrIdleTimeout = errors.New("port forward idle timeout")

ErrIdleTimeout is returned by PortForward / ReversePortForward when the forwarder shuts down because it stayed idle longer than the configured EXIT_AFTER_TIMEOUT. Callers that want to treat idle-timeout as a clean exit should check for this error with errors.Is.

Functions

func AddPrivateKeysToAgent

func AddPrivateKeysToAgent(ctx context.Context) error

func ConfigFromKeyBytes

func ConfigFromKeyBytes(keyBytes []byte) (*ssh.ClientConfig, error)

func ConfigureSSHConfig

func ConfigureSSHConfig(params SSHConfigParams) error

func FindPrivateKeys

func FindPrivateKeys() ([]string, error)

func GetDevsyHostKey

func GetDevsyHostKey() (string, error)

func GetDevsyKeysDir

func GetDevsyKeysDir() (string, error)

func GetDevsyPrivateKeyRaw

func GetDevsyPrivateKeyRaw() ([]byte, error)

func GetDevsyPublicKey

func GetDevsyPublicKey() (string, error)

func GetHostKey

func GetHostKey(context, workspaceID string) (string, error)

func GetHostKeyBase

func GetHostKeyBase(dir string) (string, error)

func GetPrivateKeyRaw

func GetPrivateKeyRaw(context, workspaceID string) ([]byte, error)

func GetPrivateKeyRawBase

func GetPrivateKeyRawBase(dir string) ([]byte, error)

func GetPublicKey

func GetPublicKey(context, workspaceID string) (string, error)

func GetPublicKeyBase

func GetPublicKeyBase(dir string) (string, error)

func GetUser

func GetUser(
	workspaceID string,
	sshConfigPath string,
	sshConfigIncludePath string,
) (string, error)

func NewSSHClient

func NewSSHClient(user, addr string, keyBytes []byte) (*ssh.Client, error)

func NewSSHPassClient

func NewSSHPassClient(user, addr, password string) (*ssh.Client, error)

func PortForward

func PortForward(
	ctx context.Context,
	client *ssh.Client,
	localNetwork, localAddr, remoteNetwork, remoteAddr string,
	exitAfterTimeout time.Duration,
) error

func PortForwardWithListener added in v1.3.1

func PortForwardWithListener(
	ctx context.Context,
	client *ssh.Client,
	opts ForwardOpts,
) error

PortForwardWithListener is like PortForward, but uses a caller-supplied listener instead of binding one internally. This lets the caller reserve the local port before forking, eliminating a TOCTOU race between port probe and net.Listen in a detached child. The remote network is always "tcp".

func RemoveFromConfig

func RemoveFromConfig(
	workspaceID string,
	sshConfigPath string,
	sshConfigIncludePath string,
) error

func ResolveSSHConfigPath

func ResolveSSHConfigPath(sshConfigPath string) (string, error)

func ReversePortForward

func ReversePortForward(
	ctx context.Context,
	client *ssh.Client,
	remoteNetwork, remoteAddr, localNetwork, localAddr string,
	exitAfterTimeout time.Duration,
) error

func Run

func Run(ctx context.Context, opts RunOptions) error

func StdioClient

func StdioClient(reader io.Reader, writer io.WriteCloser, exitOnClose bool) (*ssh.Client, error)

func StdioClientFromKeyBytesWithUser

func StdioClientFromKeyBytesWithUser(
	keyBytes []byte,
	reader io.Reader,
	writer io.WriteCloser,
	user string,
	exitOnClose bool,
) (*ssh.Client, error)

func StdioClientWithUser

func StdioClientWithUser(
	reader io.Reader,
	writer io.WriteCloser,
	user string,
	exitOnClose bool,
) (*ssh.Client, error)

func WatchWindowSize

func WatchWindowSize(ctx context.Context) <-chan os.Signal

Types

type DevsySSHEntry

type DevsySSHEntry struct {
	Host      string
	User      string
	Workspace string
}

type ExitError

type ExitError struct {
	ExitCode int
	Err      error
}

ExitError wraps an SSH exit error with the exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

type ForwardOpts added in v1.3.1

type ForwardOpts struct {
	Listener         net.Listener
	RemoteAddr       string
	ExitAfterTimeout time.Duration
}

ForwardOpts groups the parameters for PortForwardWithListener so callers don't have to thread a long positional argument list.

type ForwardingFunction

type ForwardingFunction func(
	net.Conn,
	*ssh.Client,
	string,
	string,
)

type RunOptions

type RunOptions struct {
	Client  *ssh.Client
	Command string
	Stdin   io.Reader
	Stdout  io.Writer
	Stderr  io.Writer
	EnvVars map[string]string
}

type SSHConfigParams

type SSHConfigParams struct {
	SSHConfigPath        string
	SSHConfigIncludePath string
	Context              string
	Workspace            string
	User                 string
	Workdir              string
	Command              string
	GPGAgent             bool
	DevsyHome            string
	Provider             string
	TunnelPort           int // If > 0, use TCP tunnel mode instead of ProxyCommand
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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