Documentation
¶
Index ¶
- func BuildAutoAuthMethods(user, host string, passwordCallback func(string)) ([]ssh.AuthMethod, func())
- func StartKeepAlive(client *ssh.Client, interval time.Duration, fallback func(err error))
- type AuthMethod
- type Client
- func (c *Client) Close() error
- func (c *Client) LocalForward(ctx context.Context, localAddr, remoteAddr string) error
- func (c *Client) Node() models.Node
- func (c *Client) RemoteForward(ctx context.Context, remoteAddr, localAddr string) error
- func (c *Client) Run(ctx context.Context, cmd string) (string, error)
- func (c *Client) RunInteractive(ctx context.Context, cmd string) error
- func (c *Client) RunInteractiveCmd(ctx context.Context, cmd string) error
- func (c *Client) RunInteractiveWithSudo(ctx context.Context, command string) error
- func (c *Client) RunScript(ctx context.Context, scriptContent string) (string, error)
- func (c *Client) RunScriptWithSudo(ctx context.Context, scriptContent string) (string, error)
- func (c *Client) RunWithSudo(ctx context.Context, command string) (string, error)
- func (c *Client) RunWithoutLogin(ctx context.Context, cmd string) (string, error)
- func (c *Client) SSHClient() *ssh.Client
- func (c *Client) Shell(ctx context.Context) error
- func (c *Client) ShellWithSudo(ctx context.Context) error
- type Connector
- type Dialer
- type KeyAuth
- type PasswordAuth
- type SSHProxyDialer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAutoAuthMethods ¶ added in v0.5.0
func BuildAutoAuthMethods(user, host string, passwordCallback func(string)) ([]ssh.AuthMethod, func())
BuildAutoAuthMethods 生成一个包含多种回退机制的 AuthMethod 链
Types ¶
type AuthMethod ¶
type AuthMethod interface {
GetMethod() (ssh.AuthMethod, error)
}
AuthMethod 定义获取 SSH 认证方法的接口
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) LocalForward ¶ added in v0.5.0
LocalForward starts local port forwarding. Listens on localAddr, forwards connections to remoteAddr via SSH.
func (*Client) RemoteForward ¶ added in v0.5.0
RemoteForward starts remote port forwarding. Asks SSH server to listen on remoteAddr, forwards connections to localAddr.
func (*Client) RunInteractive ¶ added in v0.4.0
RunInteractive 在 PTY 环境下执行单条命令,支持交互式/流式命令 (如 tail -f, vim, top)
func (*Client) RunInteractiveCmd ¶ added in v0.6.0
RunInteractiveCmd 在 PTY 环境下直接执行命令(通过 SSH exec 通道,不启动交互式 shell), 不会产生登录信息或命令回显,适合在已有 shell 环境内调用 vim/top 等程序。
func (*Client) RunInteractiveWithSudo ¶ added in v0.4.0
RunInteractiveWithSudo 在 PTY 环境下以提权方式执行单条交互式命令
func (*Client) RunScriptWithSudo ¶
RunScriptWithSudo 提权执行脚本
func (*Client) RunWithSudo ¶
func (*Client) RunWithoutLogin ¶
RunWithoutLogin 执行命令并在非登录 Shell 中运行,避免加载 profile 脚本产生干扰输出
type Connector ¶
type Connector struct {
Config config.ConfigProvider
// contains filtered or unexported fields
}
Connector 负责创建 SSH 连接
func NewConnector ¶
func NewConnector(cfg config.ConfigProvider) *Connector
NewConnector 创建一个新的 Connector
type Dialer ¶
type Dialer interface {
Dial(network, addr string) (net.Conn, error)
DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}
Dialer 定义网络连接行为的接口 用于统一 "直连" 和 "通过 SSH 跳板机连接" 的行为
type PasswordAuth ¶
type PasswordAuth struct {
Password string
}
PasswordAuth 实现密码认证
func (*PasswordAuth) GetMethod ¶
func (p *PasswordAuth) GetMethod() (ssh.AuthMethod, error)
type SSHProxyDialer ¶
SSHProxyDialer 实现了 Dialer 接口,通过 SSH 隧道转发流量