sshhelper

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFileToRemoteScp

func CopyFileToRemoteScp(client *ssh.Client, src, rDir, rName string, permission uint32) error

src is the local file path, rDir is the remote directory path, rName is the remote file name.

func GetParentDir

func GetParentDir(path string) string

GetParentDir returns the parent directory of a Unix-style path

func ParsePublicKeyFromAny

func ParsePublicKeyFromAny(keyData []byte) (ssh.PublicKey, error)

Types

type Client

type Client struct {
	*ssh.Client
	Password string

	sync.Mutex
	// contains filtered or unexported fields
}

func Dial

func Dial(s *DialConfig) (*Client, []byte, error)

func (*Client) AllowAllInbound

func (c *Client) AllowAllInbound() error

AllowAllInbound sets the firewall to allow all inbound connections WARNING: This is insecure and should only be used for testing

func (*Client) AppendToFile

func (c *Client) AppendToFile(path, content string, sudo bool) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) ClosePort

func (c *Client) ClosePort(port uint32, protocol string) error

ClosePort denies/blocks inbound traffic to a specific port with the given protocol (tcp/udp)

func (*Client) ClosePorts

func (c *Client) ClosePorts(ports []uint32, protocol string) error

ClosePorts closes multiple ports for the given protocol (tcp/udp) This is a bulk operation that calls ClosePort for each port

func (*Client) CombinedOutput

func (c *Client) CombinedOutput(command string, sudo bool) (string, error)

Returns output and error

func (*Client) CommandExists

func (c *Client) CommandExists(command string, sudo bool) (bool, error)

func (*Client) CopyContentToRemote

func (c *Client) CopyContentToRemote(src io.Reader, dst string, permission uint32) error

func (*Client) CopyContentToRemoteSudo

func (c *Client) CopyContentToRemoteSudo(src io.Reader, dst string, permission uint32) error

func (*Client) CopyFileToRemoteSftp

func (c *Client) CopyFileToRemoteSftp(src, dst string, permission uint32) error

src is the local file path, dst is the remote file path. permision is fs.FileMode if dst file already exists, it will be overwritten.

func (*Client) CopyFileToRemoteSftpSudo

func (c *Client) CopyFileToRemoteSftpSudo(src, dst string, permission uint32) error

copy file to tmp folder, then move to dst using sudo

func (*Client) CreateDir

func (c *Client) CreateDir(path string, sudo bool) error

create folder specified by path, if already existed, do nothing.

func (*Client) DeletePortRule

func (c *Client) DeletePortRule(port uint32, protocol string) error

DeletePortRule removes a firewall rule for a specific port This operation is idempotent - it won't error if the rule doesn't exist

func (*Client) DeletePortRules

func (c *Client) DeletePortRules(ports []uint32, protocol string) error

DeletePortRules deletes firewall rules for multiple ports This is a bulk operation that calls DeletePortRule for each port

func (*Client) DetectFirewall

func (c *Client) DetectFirewall() (FirewallType, error)

DetectFirewall determines which firewall system is active on the remote server

func (*Client) DirExist

func (c *Client) DirExist(path string) (bool, error)

func (*Client) DisableFirewall

func (c *Client) DisableFirewall() error

DisableFirewall disables the firewall service

func (*Client) Download

func (c *Client) Download(output, url string, sudo bool) error

download file from url to output using curl if path existed, it will be replaced by the new file

func (*Client) DownloadRemoteFileToLocal

func (c *Client) DownloadRemoteFileToLocal(remotePath, localPath string) error

func (*Client) DownloadRemoteFileToMemory added in v1.0.1

func (c *Client) DownloadRemoteFileToMemory(remotePath string) ([]byte, error)

func (*Client) EnableBbr

func (c *Client) EnableBbr() error

func (*Client) EnableFirewall

func (c *Client) EnableFirewall() error

EnableFirewall enables the firewall service

func (*Client) FileExisted

func (c *Client) FileExisted(path string) (bool, error)

func (*Client) GetFirewallStatus

func (c *Client) GetFirewallStatus() (string, error)

GetFirewallStatus returns the firewall status and rules

func (*Client) GetOSArch

func (c *Client) GetOSArch() (os string, arch string, err error)

func (*Client) GetServerOS

func (c *Client) GetServerOS() (string, error)

func (*Client) GetSftpClient

func (c *Client) GetSftpClient() (*sftp.Client, error)

func (*Client) OpenPort

func (c *Client) OpenPort(port uint32, protocol string) error

OpenPort allows inbound traffic to a specific port with the given protocol (tcp/udp) This operation is idempotent - it checks if the rule already exists before adding

func (*Client) OpenPorts

func (c *Client) OpenPorts(ports []uint32, protocol string) error

OpenPorts opens multiple ports for the given protocol (tcp/udp) This is a bulk operation that calls OpenPort for each port

func (*Client) Output

func (c *Client) Output(command string, sudo bool) (string, error)

Returns error

func (*Client) PackageManager

func (c *Client) PackageManager() (string, error)

func (*Client) PathExisted

func (c *Client) PathExisted(path string) (bool, error)

func (*Client) Reboot

func (c *Client) Reboot() error

func (*Client) Run

func (c *Client) Run(command string, sudo bool) error

func (*Client) ServiceStatus

func (c *Client) ServiceStatus(name string) (*ServiceStatus, error)

func (*Client) ShRun

func (c *Client) ShRun(command string, sudo bool) error

client.CombinedOutput("sh -c 'curl -fsSL https://get.docker.com | sh'", true)

func (*Client) Shutdown

func (c *Client) Shutdown() error

func (*Client) StdOutAndStdErr

func (c *Client) StdOutAndStdErr(command string, sudo bool) (string, string, error)

Returns error

func (*Client) Suspend

func (c *Client) Suspend() error

type DialConfig

type DialConfig struct {
	Addr                 string
	User                 string
	Password             string
	PrivateKey           []byte
	PrivateKeyPassphrase string
	HostKey              []byte
}

type FirewallType

type FirewallType string

FirewallType represents the type of firewall system

const (
	FirewallUFW       FirewallType = "ufw"
	FirewallFirewalld FirewallType = "firewalld"
	FirewallIptables  FirewallType = "iptables"
	FirewallNftables  FirewallType = "nftables"
	FirewallUnknown   FirewallType = "unknown"
)

type ServiceStatus

type ServiceStatus struct {
	Running bool
	StartAt string  // unix timestamp
	Memory  float32 // MB
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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