Documentation ¶
Index ¶
- Variables
- func AddKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (err error)
- func CheckKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (found bool, err error)
- func DefaultKnownHosts() (ssh.HostKeyCallback, error)
- func DefaultKnownHostsPath() (string, error)
- func Dial(proto string, c *Config) (*ssh.Client, error)
- func GetSigner(prvFile string, passphrase string) (ssh.Signer, error)
- func HasAgent() bool
- func KnownHosts(file string) (ssh.HostKeyCallback, error)
- type Auth
- type AutoPrompt
- type Client
- func (c Client) Close() error
- func (c Client) Command(name string, args ...string) (*Cmd, error)
- func (c Client) CommandContext(ctx context.Context, name string, args ...string) (*Cmd, error)
- func (c Client) Download(remotePath string, localPath string) (err error)
- func (c Client) NewSftp(opts ...sftp.ClientOption) (*sftp.Client, error)
- func (c Client) Run(cmds ...string) ([]byte, error)
- func (c Client) RunContext(ctx context.Context, name string) ([]byte, error)
- func (conn *Client) RunWithAutoPrompt(autoPrompts []AutoPrompt, cmds ...string) ([]byte, error)
- func (c Client) Upload(localPath string, remotePath string) (err error)
- type Cmd
- type Config
Constants ¶
This section is empty.
Variables ¶
var DefaultTimeout = 20 * time.Second
DefaultTimeout is the timeout of ssh client connection.
Functions ¶
func AddKnownHost ¶
AddKnownHost add a a host to known hosts file.
func CheckKnownHost ¶
func CheckKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (found bool, err error)
CheckKnownHost checks is host in known hosts file. it returns is the host found in known_hosts file and error, if the host found in known_hosts file and error not nil that means public key mismatch, maybe MAN IN THE MIDDLE ATTACK! you should not handshake.
func DefaultKnownHosts ¶
func DefaultKnownHosts() (ssh.HostKeyCallback, error)
DefaultKnownHosts returns host key callback from default known hosts path, and error if any.
func DefaultKnownHostsPath ¶
DefaultKnownHostsPath returns default user knows hosts file.
func KnownHosts ¶
func KnownHosts(file string) (ssh.HostKeyCallback, error)
KnownHosts returns host key callback from a custom known hosts path.
Types ¶
type Auth ¶
type Auth []ssh.AuthMethod
Auth represents ssh auth methods.
type AutoPrompt ¶
AutoPrompt for RunWithAutoPrompt.
type Client ¶
Client represents Goph client.
func NewUnknown ¶
NewUnknown starts a ssh connection get client without cheking knownhosts. PLEASE AVOID USING THIS, UNLESS YOU KNOW WHAT ARE YOU DOING! if there a "man in the middle proxy", this can harm you! You can add the key to know hosts and use New() func instead!
func (Client) CommandContext ¶
Command returns new Cmd with context and error, if any.
func (Client) Run ¶
Run starts a new SSH session and runs the cmd, it returns CombinedOutput and err if any.
func (Client) RunContext ¶
Run starts a new SSH session with context and runs the cmd. It returns CombinedOutput and err if any.
func (*Client) RunWithAutoPrompt ¶
func (conn *Client) RunWithAutoPrompt(autoPrompts []AutoPrompt, cmds ...string) ([]byte, error)
type Cmd ¶
type Cmd struct { // Path to command executable filename Path string // Command args. Args []string // Session env vars. Env []string // SSH session. *ssh.Session // Context for cancellation Context context.Context }
Cmd it's like os/exec.Cmd but for ssh session.
func (*Cmd) CombinedOutput ¶
CombinedOutput runs cmd on the remote host and returns its combined stdout and stderr.