sshutils

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SSH_CONNECT_ATTEMPT_DELAY time.Duration = 5 * time.Second
)

Variables

View Source
var (
	ErrNoneOfConstructorArgsCanBeEmpty = errors.New("none of the arguments can be empty; neither 'hostName', 'userName', 'sshPassword', 'sshKeyPath', 'hostPublicKey'")
)

Functions

func ParseSSHPublicKey added in v0.1.11

func ParseSSHPublicKey(key string) (gossh.PublicKey, error)

ParseSSHPublicKey parses an SSH public key string in authorized_keys format and returns the parsed PublicKey. This can be used to validate the key early (e.g. during configuration) before passing it to NewStandardSshManager.

Types

type SSHKeyParser added in v0.1.8

type SSHKeyParser interface {
	Parse(keyPath string) gossh.Signer
}

SSHKeyParser defines the interface for parsing an SSH key from a path.

func NewFileSSHKeyParser added in v0.1.8

func NewFileSSHKeyParser() SSHKeyParser

NewFileSSHKeyParser creates a new parser that reads from the filesystem.

type SshManager

type SshManager interface {
	IsInit() bool
	ExchangeKeys() error
	ExecuteScript(scriptPath, scriptContent string, postRemove bool, runWithSudo bool) error
	WriteFileOnRemoteMachine(path, fileContent string, fileMode os.FileMode) error
	DisablePasswordSSHLogin() error
	RebootCloudInit() error
	RegisterOS(regcode, email string) error
	DeregisterOS() error
}

SshManager interface defines the methods for interacting with the SSH Manager.

type StandardSshManager

type StandardSshManager struct {
	HostName      string
	UserName      string
	SshPassword   string
	SshKeyPath    string
	Client        ssh.Client
	HostPublicKey gossh.PublicKey
	// contains filtered or unexported fields
}

StandardSshManager struct holds configuration for SSH Manager interaction.

func NewStandardSshManager

func NewStandardSshManager(hostName, userName, sshPassword, sshKeyPath string, hostPublicKey gossh.PublicKey) (*StandardSshManager, error)

NewStandardSshManager Returns new instance of Standard SSH Manager and error. The hostPublicKey parameter must be a pre-parsed gossh.PublicKey (use ParseSSHPublicKey to obtain one).

func (*StandardSshManager) DeregisterOS added in v0.1.8

func (sc *StandardSshManager) DeregisterOS() error

DeregisterOS - De-registers SLES OS using SUSEConnect

func (*StandardSshManager) DisablePasswordSSHLogin

func (sc *StandardSshManager) DisablePasswordSSHLogin() error

DisablePasswordSSHLogin disables password authentication for SSH on newly created machine

func (*StandardSshManager) ExchangeKeys

func (sc *StandardSshManager) ExchangeKeys() error

func (*StandardSshManager) ExecuteScript

func (sc *StandardSshManager) ExecuteScript(scriptPath, scriptContent string, postRemove, runWithSudo bool) error

ExecuteScript Executes script defined by path and content. Executing procedure consists of few steps:

  • if script path is not set (empty), then create a secure temporary subdirectory (e.g. /tmp/fsas-nodedriver) with minimal permissions and prepare the script using a random filename inside that directory (e.g. /tmp/fsas-nodedriver/username-via-ssh-256.sh)
  • generate file in above location with given content and grant executable privileges to file
  • execute script
  • if param 'postRemove' is true then:
  • remove script after execution else leave it
  • delete secure directory if it is empty.
  • if script path is provided, the script is written and executed at that path without directory creation or deletion.

func (*StandardSshManager) IsInit

func (sc *StandardSshManager) IsInit() bool

IsInit Returns true if constructor succeed else false

func (*StandardSshManager) RebootCloudInit

func (sc *StandardSshManager) RebootCloudInit() error

RebootCloudInit() error

func (*StandardSshManager) RegisterOS added in v0.1.8

func (sc *StandardSshManager) RegisterOS(regcode, email string) error

RegisterOS - Registers SLES OS license using SUSEConnect

func (*StandardSshManager) String

func (sc *StandardSshManager) String() string

func (*StandardSshManager) WriteFileOnRemoteMachine

func (sc *StandardSshManager) WriteFileOnRemoteMachine(path, fileContent string, fileMode os.FileMode) error

WriteFileOnRemoteMachine Writes content to file defined in path

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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