Skip to main content

ssh

函数名函数描述/介绍
ssh.ConnectSSHConnect establishes an SSH connection with flexible options
ssh.ConnectWithKeySSHConnectWithKey connects to SSH server using private key
ssh.ConnectWithPasswdSSHConnectWithPasswd connects to SSH server using password
ssh.keyPassphraseWithSSHKeyPassphrase sets the passphrase for encrypted private key
ssh.passwordWithSSHPassword sets the SSH password
ssh.portWithSSHPort sets the SSH port
ssh.privateKeyWithSSHPrivateKey sets the path to SSH private key
ssh.timeoutWithSSHTimeout sets the connection timeout in seconds
ssh.usernameWithSSHUsername sets the SSH username

函数定义#

Connect#

详细描述#

SSHConnect establishes an SSH connection with flexible options

Example:

client, err = ssh.Connect("example.com:22", ssh.username("root"), ssh.password("pass"))client, err = ssh.Connect("example.com", ssh.username("admin"), ssh.privateKey("/path/to/key"))

定义#

Connect(host string, opts ...SSHOption) (*SSHClient, error)

参数#

参数名参数类型参数解释
hoststring
opts...SSHOption

返回值#

返回值(顺序)返回值类型返回值解释
r1*SSHClient
r2error

ConnectWithKey#

详细描述#

SSHConnectWithKey connects to SSH server using private key

Example:

client, err = ssh.ConnectWithKey("example.com:22", "root", "/path/to/id_rsa")

定义#

ConnectWithKey(host string, username string, keyPath string) (*SSHClient, error)

参数#

参数名参数类型参数解释
hoststring
usernamestring
keyPathstring

返回值#

返回值(顺序)返回值类型返回值解释
r1*SSHClient
r2error

ConnectWithPasswd#

详细描述#

SSHConnectWithPasswd connects to SSH server using password

Example:

client, err = ssh.ConnectWithPasswd("example.com:22", "root", "password")

定义#

ConnectWithPasswd(host string, username string, password string) (*SSHClient, error)

参数#

参数名参数类型参数解释
hoststring
usernamestring
passwordstring

返回值#

返回值(顺序)返回值类型返回值解释
r1*SSHClient
r2error

keyPassphrase#

详细描述#

WithSSHKeyPassphrase sets the passphrase for encrypted private key

定义#

keyPassphrase(passphrase string) SSHOption

参数#

参数名参数类型参数解释
passphrasestring

返回值#

返回值(顺序)返回值类型返回值解释
r1SSHOption

password#

详细描述#

WithSSHPassword sets the SSH password

定义#

password(password string) SSHOption

参数#

参数名参数类型参数解释
passwordstring

返回值#

返回值(顺序)返回值类型返回值解释
r1SSHOption

port#

详细描述#

WithSSHPort sets the SSH port

定义#

port(port int) SSHOption

参数#

参数名参数类型参数解释
portint

返回值#

返回值(顺序)返回值类型返回值解释
r1SSHOption

privateKey#

详细描述#

WithSSHPrivateKey sets the path to SSH private key

定义#

privateKey(keyPath string) SSHOption

参数#

参数名参数类型参数解释
keyPathstring

返回值#

返回值(顺序)返回值类型返回值解释
r1SSHOption

timeout#

详细描述#

WithSSHTimeout sets the connection timeout in seconds

定义#

timeout(timeout float64) SSHOption

参数#

参数名参数类型参数解释
timeoutfloat64

返回值#

返回值(顺序)返回值类型返回值解释
r1SSHOption

username#

详细描述#

WithSSHUsername sets the SSH username

定义#

username(username string) SSHOption

参数#

参数名参数类型参数解释
usernamestring

返回值#

返回值(顺序)返回值类型返回值解释
r1SSHOption