ssh

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RequiredTools = []string{"ssh", "sftp", "ssh-keygen"}

RequiredTools lists the OpenSSH tools needed by SSHThing

Functions

func CheckPrereqs

func CheckPrereqs() error

CheckPrereqs verifies that required OpenSSH tools are available in PATH. Returns nil if all tools are found, otherwise returns an error with installation instructions appropriate for the current platform.

func CheckSFTP

func CheckSFTP() error

CheckSFTP verifies that sftp is available

func CheckSSH

func CheckSSH() error

CheckSSH verifies that ssh is available

func CheckSSHKeygen

func CheckSSHKeygen() error

CheckSSHKeygen verifies that ssh-keygen is available

func CheckSSHPass added in v1.0.3

func CheckSSHPass() error

CheckSSHPass verifies that sshpass is available.

func GenerateKey

func GenerateKey(keyType KeyType, comment string) (privateKey, publicKey string, err error)

GenerateKey generates a new SSH key pair using ssh-keygen. Returns the private key content and the public key content.

func GetPublicKeyFromPrivate

func GetPublicKeyFromPrivate(privateKey string) (string, error)

GetPublicKeyFromPrivate extracts the public key from a private key using ssh-keygen.

func HasTool added in v1.0.3

func HasTool(name string) bool

HasTool returns true when a binary is present in PATH.

func IsAskpassInvocation added in v1.0.3

func IsAskpassInvocation() bool

IsAskpassInvocation returns true when this process was launched as askpass helper.

func RunAskpassHelper added in v1.0.3

func RunAskpassHelper() error

RunAskpassHelper prints a one-time password to stdout for OpenSSH askpass usage.

func RunSSH

func RunSSH(conn Connection) error

RunSSH runs an SSH session and waits for it to complete. It handles cleanup of the temporary key file automatically.

func RunSSHExec added in v1.0.5

func RunSSHExec(conn Connection, remoteCommand string) error

RunSSHExec runs a non-interactive remote command over SSH and waits for completion.

func ValidatePrivateKey

func ValidatePrivateKey(key string) error

ValidatePrivateKey checks if a string looks like a valid SSH private key.

Types

type Connection

type Connection struct {
	Hostname   string
	Username   string
	Port       int
	PrivateKey string // Decrypted private key content
	Password   string // Decrypted password secret for password auth

	PasswordBackendUnix string // "sshpass_first" | "askpass_first"

	// Options
	HostKeyPolicy    string // "accept-new" | "strict" | "off"
	KeepAliveSeconds int
	Term             string // optional TERM override (env SSHTHING_SSH_TERM still wins)
}

Connection represents an SSH connection configuration

type KeyType

type KeyType string

KeyType represents the type of SSH key to generate

const (
	KeyTypeEd25519 KeyType = "ed25519"
	KeyTypeRSA     KeyType = "rsa"
	KeyTypeECDSA   KeyType = "ecdsa"
)

type TempKeyFile

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

TempKeyFile manages a temporary file for the SSH private key

func Connect

func Connect(conn Connection) (*exec.Cmd, *TempKeyFile, error)

Connect establishes an SSH connection. It returns the exec.Cmd that can be used to run the SSH session. The caller is responsible for cleaning up the temp key file after the session ends.

func ConnectExec added in v1.0.5

func ConnectExec(conn Connection, remoteCommand string) (*exec.Cmd, *TempKeyFile, error)

ConnectExec establishes a non-interactive SSH command execution session. The remote command is passed as a single argument to ssh after the target host.

func ConnectSFTP

func ConnectSFTP(conn Connection) (*exec.Cmd, *TempKeyFile, error)

ConnectSFTP establishes an interactive SFTP session using the system `sftp` client. It returns the exec.Cmd that can be used to run the session and any temp key file that must be cleaned up after exit.

func NewTempKeyFile

func NewTempKeyFile(privateKey string) (*TempKeyFile, error)

NewTempKeyFile creates a secure temporary file for the private key. The file is created with 600 permissions (owner read/write only).

func (*TempKeyFile) Cleanup

func (t *TempKeyFile) Cleanup() error

Cleanup securely removes the temporary key file

func (*TempKeyFile) Path

func (t *TempKeyFile) Path() string

Path returns the path to the temporary key file

Jump to

Keyboard shortcuts

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