Documentation
¶
Index ¶
- func CopyFileToRemoteScp(client *ssh.Client, src, rDir, rName string, permission uint32) error
- func GetParentDir(path string) string
- func ParsePublicKeyFromAny(keyData []byte) (ssh.PublicKey, error)
- type Client
- func (c *Client) AllowAllInbound() error
- func (c *Client) AppendToFile(path, content string, sudo bool) error
- func (c *Client) Close() error
- func (c *Client) ClosePort(port uint32, protocol string) error
- func (c *Client) ClosePorts(ports []uint32, protocol string) error
- func (c *Client) CombinedOutput(command string, sudo bool) (string, error)
- func (c *Client) CommandExists(command string, sudo bool) (bool, error)
- func (c *Client) CopyContentToRemote(src io.Reader, dst string, permission uint32) error
- func (c *Client) CopyContentToRemoteSudo(src io.Reader, dst string, permission uint32) error
- func (c *Client) CopyFileToRemoteSftp(src, dst string, permission uint32) error
- func (c *Client) CopyFileToRemoteSftpSudo(src, dst string, permission uint32) error
- func (c *Client) CreateDir(path string, sudo bool) error
- func (c *Client) DeletePortRule(port uint32, protocol string) error
- func (c *Client) DeletePortRules(ports []uint32, protocol string) error
- func (c *Client) DetectFirewall() (FirewallType, error)
- func (c *Client) DirExist(path string) (bool, error)
- func (c *Client) DisableFirewall() error
- func (c *Client) DownloadRemoteFileToLocal(remotePath, localPath string) error
- func (c *Client) DownloadRemoteFileToLocalSudo(remotePath, localPath string) error
- func (c *Client) DownloadRemoteFileToMemory(remotePath string) ([]byte, error)
- func (c *Client) DownloadRemoteFileToMemorySudo(remotePath string) ([]byte, error)
- func (c *Client) DownloadUrl(url, path string) error
- func (c *Client) EnableBbr() error
- func (c *Client) FileExisted(path string) (bool, error)
- func (c *Client) GetFirewallStatus() (string, error)
- func (c *Client) GetOSArch() (os string, arch string, err error)
- func (c *Client) GetServerOS() (string, error)
- func (c *Client) GetSftpClient() (*sftp.Client, error)
- func (c *Client) HasPasswordlessSudo() (bool, error)
- func (c *Client) IsRoot() (bool, error)
- func (c *Client) OpenPort(port uint32, protocol string) error
- func (c *Client) OpenPorts(ports []uint32, protocol string) error
- func (c *Client) Output(command string, sudo bool) (string, error)
- func (c *Client) PackageManager() (string, error)
- func (c *Client) PathExisted(path string) (bool, error)
- func (c *Client) Reboot() error
- func (c *Client) Run(command string, sudo bool) error
- func (c *Client) ServiceStatus(name string) (*ServiceStatus, error)
- func (c *Client) ShRun(command string) error
- func (c *Client) Shutdown() error
- func (c *Client) StdOutAndStdErr(command string, sudo bool) (string, string, error)
- func (c *Client) Suspend() error
- type DialConfig
- type FirewallType
- type ServiceStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyFileToRemoteScp ¶
src is the local file path, rDir is the remote directory path, rName is the remote file name.
func GetParentDir ¶
GetParentDir returns the parent directory of a Unix-style path
Types ¶
type Client ¶
type Client struct {
*ssh.Client
Password string
sync.Mutex
// contains filtered or unexported fields
}
func (*Client) AllowAllInbound ¶
AllowAllInbound sets the firewall to allow all inbound connections The setting is persistent
func (*Client) ClosePort ¶
ClosePort denies/blocks inbound traffic to a specific port with the given protocol (tcp/udp)
func (*Client) ClosePorts ¶
ClosePorts closes multiple ports for the given protocol (tcp/udp) This is a bulk operation that calls ClosePort for each port
func (*Client) CombinedOutput ¶
Returns output and error
func (*Client) CommandExists ¶
func (*Client) CopyContentToRemote ¶
func (*Client) CopyContentToRemoteSudo ¶
func (*Client) CopyFileToRemoteSftp ¶
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 ¶
copy file to tmp folder, then move to dst using sudo
func (*Client) DeletePortRule ¶
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 ¶
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) DisableFirewall ¶
DisableFirewall disables the firewall service or allow inbound traffic so that incoming connections are allowed.
func (*Client) DownloadRemoteFileToLocal ¶
func (*Client) DownloadRemoteFileToLocalSudo ¶ added in v1.2.4
DownloadRemoteFileToLocalSudo writes the contents of a root-only (or otherwise privileged) remote file to localPath. See DownloadRemoteFileToMemorySudo.
func (*Client) DownloadRemoteFileToMemory ¶ added in v1.0.1
func (*Client) DownloadRemoteFileToMemorySudo ¶ added in v1.2.4
DownloadRemoteFileToMemorySudo reads remotePath with elevated privileges via the remote shell (sudo cat). Use when the file is not readable by the SSH user and SFTP (DownloadRemoteFileToMemory) fails. Binary-safe.
func (*Client) DownloadUrl ¶ added in v1.0.8
DownloadUrl downloads a file from the given URL to the given path on the remote machine.
func (*Client) GetFirewallStatus ¶
GetFirewallStatus returns the firewall status and rules
func (*Client) GetServerOS ¶
func (*Client) HasPasswordlessSudo ¶ added in v1.0.4
func (*Client) IsRoot ¶ added in v1.0.4
IsRoot checks if the current user is root (UID 0) or has sudo privileges Returns true if:
- The user is already root (id -u returns 0)
Returns false otherwise
func (*Client) OpenPort ¶
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 ¶
OpenPorts opens multiple ports for the given protocol (tcp/udp) This is a bulk operation that calls OpenPort for each port
func (*Client) PackageManager ¶
func (*Client) ServiceStatus ¶
func (c *Client) ServiceStatus(name string) (*ServiceStatus, error)
func (*Client) ShRun ¶
client.CombinedOutput("sh -c 'curl -fsSL https://get.docker.com | sh'", true) This is for applying sudo to joined command. If non-root users, use sudo and sh -c to run command. If root users, just run the command.
func (*Client) StdOutAndStdErr ¶
Returns error
type DialConfig ¶
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" )