ssh

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 7 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 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 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 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 // For password auth (not recommended)

	// 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 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