ssh

package
v0.0.0-...-275f270 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddKnownHost

func AddKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (err error)

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

func DefaultKnownHostsPath() (string, error)

DefaultKnownHostsPath returns default user knows hosts file.

func PasswordKey

func PasswordKey(username string, password string, timeout int) *ssh.ClientConfig

Creates a configuration for a client that authenticates using username and password

func PrivateKey

func PrivateKey(username string, path string, timeout int) (*ssh.ClientConfig, error)

PrivateKey Loads a private and public key from "path" and returns a SSH ClientConfig to authenticate with the server

func PrivateKeyWithPassphrase

func PrivateKeyWithPassphrase(username string, timeout int, passpharase []byte, path string) (*ssh.ClientConfig, error)

Creates the configuration for a client that authenticates with a password protected private key

func SSHAgent

func SSHAgent(username string, timeout int, keyCallBack ssh.HostKeyCallback) (*ssh.ClientConfig, error)

Creates a configuration for a client that fetches public-private key from the SSH agent for authentication

Types

type SSHClient

type SSHClient struct {
	Addr   string
	Config *ssh.ClientConfig
	*ssh.Client
}

SSHClient represents Goph client.

func NewSSHClient

func NewSSHClient(server, port string, config *ssh.ClientConfig) (c *SSHClient)

NewConn returns new client and error if any.

func (SSHClient) Download

func (c SSHClient) Download(remotePath string, localPath string) error

Download file from remote server!

func (SSHClient) NewSftp

func (c SSHClient) NewSftp(opts ...sftp.ClientOption) (*sftp.Client, error)

NewSftp returns new sftp client and error if any.

func (SSHClient) Run

func (c SSHClient) Run(cmd string) ([]byte, error)

Run starts a new SSH session and runs the cmd, it returns CombinedOutput and err if any.

func (SSHClient) Upload

func (c SSHClient) Upload(localPath string, remoteDir string) (err error)

Upload a local file or directory to remote server!

type WriteCounter

type WriteCounter struct {
	Total int64 // Total # of bytes written
}

func (*WriteCounter) Write

func (wc *WriteCounter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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