sssh

package module
v0.0.0-...-3265b99 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2020 License: MIT Imports: 9 Imported by: 0

README

sssh (simple ssh)

A wrapper to golang.org/x/crypto/ssh to simplify session creation

This package provides a wrapper that simplifies creating an ssh session.

The package supports creating a session, authenticated via username/password or username/private key, with optional socks5 proxy.

This is roughly equivalent to an ssh connection with the following options:

Host hostname
  ProxyCommand /usr/bin/nc -x proxyserver:port %h %p
  User username
  IdentityFile privatekey-file

To use, create a new session:

session, err := sssh.NewSession("somehost:22",
	                        sssh.User(username),
	                        sssh.Password(password))
    if err != nil {
        ...
    }
defer session.Close()

Then use one of the methods in ssh.Session (https://godoc.org/golang.org/x/crypto/ssh#Session):

if err = session.Run("ls -l"); err != nil {
	...
}

Additional documentation is available at https://godoc.org/github.com/gobs/sssh.

A working example is available in the cmd/sssh subfolder.

Documentation

Overview

Package sssh (simple ssh) provides a wrapper that simplifies creating an ssh session (using golang.org/x/crypto/ssh).

The package supports creating a session, authenticated via username/password or username/private key, with optional socks5 proxy or jump proxy.

This is roughly equivalent to an ssh connection with the following options:

Host hostname
  ProxyCommand /usr/bin/nc -x proxyserver:port %h %p
  User username
  IdentityFile privatekey-file

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDir           = fmt.Errorf("source is a directory")
	ErrRemote        = fmt.Errorf("remote error")
	ErrRemoteFatal   = fmt.Errorf("remote fatal error")
	ErrRemoteUnknown = fmt.Errorf("remote unknown error")
)

Functions

func Copy

func Copy(client *ssh.Client, dest, src string, size int64, perm os.FileMode, reader io.Reader) error

func CopyFile

func CopyFile(client *ssh.Client, dest, src string) error

func NewClient

func NewClient(host string, options ...ConnectOption) (*ssh.Client, error)

NewClient creates a new ssh client/connection to host (host:port) with the specified options

func NewSession

func NewSession(host string, options ...ConnectOption) (*ssh.Session, error)

NewSession creates a new ssh session/connection to host (host:port) with the specified options

func Shell

func Shell(client *ssh.Client) error

Types

type ConnectOption

type ConnectOption func(c *sshConfig) error

ConnectOption is the common type for NewSession options

func Banner(callback ssh.BannerCallback) ConnectOption

Banner sets the banner callback, called when the remote host sends the banner

func JumpProxy

func JumpProxy(proxy string, options ...ConnectOption) ConnectOption

JumpProxy configures the session to jump through one proxy server

func KeyboardInteractive

func KeyboardInteractive(cb KeyboardInteractiveChallenge) ConnectOption

KeyboardInteractive sets the authentication mode to keyboar/interactive

func Password

func Password(password string) ConnectOption

Password sets the user password for authentication

func PrivateKey

func PrivateKey(key []byte) ConnectOption

PrivateKey sets the private key for authentication

func PrivateKeyFile

func PrivateKeyFile(keyFile string) ConnectOption

PrivateKeyFile sets the private key file for authentication

func SocksProxy

func SocksProxy(proxy string) ConnectOption

SocksProxy sets the (socks5) proxy address (host:port)

func Timeout

func Timeout(t time.Duration) ConnectOption

Timeout sets the connection timeout

func User

func User(user string) ConnectOption

User sets the user name for authentication

type KeyboardInteractiveChallenge

type KeyboardInteractiveChallenge = ssh.KeyboardInteractiveChallenge

type KeyboardInteractiveChallenge func(user, instruction string, questions []string, echos []bool) (answers []string, err error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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