Documentation
¶
Index ¶
- Variables
- func CheckPrereqs() error
- func CheckSFTP() error
- func CheckSSH() error
- func CheckSSHKeygen() error
- func CheckSSHPass() error
- func GenerateKey(keyType KeyType, comment string) (privateKey, publicKey string, err error)
- func GetPublicKeyFromPrivate(privateKey string) (string, error)
- func HasTool(name string) bool
- func IsAskpassInvocation() bool
- func RunAskpassHelper() error
- func RunSSH(conn Connection) error
- func RunSSHExec(conn Connection, remoteCommand string) error
- func ValidatePrivateKey(key string) error
- type Connection
- type KeyType
- type TempKeyFile
Constants ¶
This section is empty.
Variables ¶
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 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 ¶
GenerateKey generates a new SSH key pair using ssh-keygen. Returns the private key content and the public key content.
func GetPublicKeyFromPrivate ¶
GetPublicKeyFromPrivate extracts the public key from a private key using ssh-keygen.
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 ¶
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 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