ssh

package
v1.0.41 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckConnectivity

func CheckConnectivity(host, user, keyPath string) error

CheckConnectivity kiểm tra SSH connection nhanh

func EnsureSSHKeyExists added in v1.0.1

func EnsureSSHKeyExists(keyPath string) (string, error)

EnsureSSHKeyExists kiểm tra xem file SSH key có tồn tại hay không. Nếu không, nó sẽ tự động sinh mã khóa Ed25519.

func ExpandKeyPath added in v1.0.1

func ExpandKeyPath(keyPath string) (string, error)

ExpandKeyPath chuyển đổi đường dẫn chứa dâu ~ thành Absolute Path

Types

type Client

type Client struct {
	Host    string
	User    string
	KeyPath string
	Port    int
	// contains filtered or unexported fields
}

Client là SSH client wrapper

func NewClient

func NewClient(host, user, keyPath string) *Client

NewClient tạo SSH client mới

func (*Client) Close

func (c *Client) Close()

Close đóng SSH connection

func (*Client) Connect

func (c *Client) Connect() error

Connect thiết lập SSH connection

func (*Client) FileExists

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

FileExists kiểm tra file/thư mục có tồn tại không

func (*Client) GetHostname

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

GetHostname lấy hostname của remote host

func (*Client) GetRawClient added in v1.0.23

func (c *Client) GetRawClient() *gossh.Client

GetRawClient lấy con trỏ gossh client gốc

func (*Client) MkdirAll

func (c *Client) MkdirAll(path string) error

MkdirAll tạo thư mục trên remote host

func (*Client) Run

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

Run chạy lệnh trên remote host, trả về output

func (*Client) RunStream

func (c *Client) RunStream(command string, stdout, stderr io.Writer) error

RunStream chạy lệnh và stream output realtime

func (*Client) RunSudo

func (c *Client) RunSudo(command string) (string, error)

RunSudo chạy lệnh với sudo

func (*Client) WriteFile

func (c *Client) WriteFile(path, content string) error

WriteFile ghi nội dung vào file trên remote host Dùng base64 encoding để tránh escape issues

Jump to

Keyboard shortcuts

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