ssh

package module
v0.0.0-...-fba728b Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2015 License: MIT Imports: 20 Imported by: 0

README

ssh

Remote CURL is an application that can make curl requests behind a jump box by establishing an SSH connection to the jump box, and then curling a route inside the jump box's network. This is intended to be used within the confines of a VPC/VPN situation.

GTN, or GoTunnel, is an application that establishes an SSH connection to a remote machine, and then establishes a connection to a remote host over a specified host:port and proxies information as if the remote service, such as MySQL, is running on the user's local machine.

Currently, in order to make this compile, you need to fix import paths. I wrote this on my own time at SessionM and have been using it there, so currently it is still part of SessionM's shared library.

Server Channel handling implementation taken from https://gist.github.com/jpillora/b480fde82bff51a06238

Documentation

Overview

Provides methods for interacting with a remote ssh server, ssh tunneling, and provides functions for file operations directly over ssh (not sftp)

Index

Constants

View Source
const (
	DefaultPort             = 2222
	DefaultNetworkInterface = "0.0.0.0"
)

Variables

View Source
var (
	CurrentUser         string
	DefaultClientConfig *ssh.ClientConfig
)
View Source
var (
	FileNotFound = errors.New("No such file or directory")
	FileExists   = errors.New("File or directory already exists")
)

errors

View Source
var (
	PasswordNotSupported  = errors.New("Password authentication is not supported on this server")
	PublicKeyNotSupported = errors.New("Public Key authentication is not supported on this server")
)

errors

View Source
var (
	DefaultServer = newDefaultServer()
)

Functions

func Copy

func Copy(conn *ssh.Client, filename, destinationPath string, data []byte) error

Copies data to a file on a remote machine over ssh with default permissions

func CopyFile

func CopyFile(filePath, destinationPath string, conn *ssh.Client) error

Copies a file from the local machine to a remote path, preserving existing permissions

func CopyWithFileMode

func CopyWithFileMode(mode os.FileMode, filename, destinationPath string, data []byte, conn *ssh.Client) error

Copies data to a file on a remote machine over ssh with a specific file mode

func CurlFromRemote

func CurlFromRemote(conn *ssh.Client, url string, args ...string) ([]byte, error)

Initiates a curl command from a remote session and returns the results

func DefaultSshHandler

func DefaultSshHandler(s SshServer)

DefaultSshHandler that takes an SshServer interface - handles the most typical SSH use case

func DoesRemoteFileExist

func DoesRemoteFileExist(conn *ssh.Client, filepath string) bool

Checks to see if the remote file exists

func Forward

func Forward(conn *ssh.Client, listener net.Listener, url string, port int, ret chan bool, forwardFunc func(conn *ssh.Client, url string, port int) (stdin io.Writer, stdout io.Reader, stderr io.Reader, err error)) error

Forwards traffic from the ssh session to and from the local listener by copying io.Writer and io.Reader writes on the forwarded session

func ForwardNetcat

func ForwardNetcat(conn *ssh.Client, url string, port int) (stdin io.Writer, stdout io.Reader, stderr io.Reader, err error)

Takes a connection, initiates a session, and returns pipes to stdin, stdout, and stderr while calling netcat to a remote machine

func GetRemoteFile

func GetRemoteFile(path string, conn *ssh.Client) (data []byte, filename string, err error)

Retrieves a remote file very inefficiently. This can be done better

func GetSshConn

func GetSshConn(url string, config *ssh.ClientConfig) (*ssh.Client, error)

Returns an SSH connection with the given config and url

func MakeRemoteDir

func MakeRemoteDir(conn *ssh.Client, dirname string) error

Makes a remote directory

func ParsePrivateKey

func ParsePrivateKey(keyPath string) (ssh.AuthMethod, error)

Parses a private key file and returns an ssh.AuthMethod

func RemoveRemoteDir

func RemoveRemoteDir(conn *ssh.Client, dirname string) error

Remotes a remote directory

func RemoveRemoteFile

func RemoveRemoteFile(conn *ssh.Client, filepath string) error

Removes a remote file

func ServeSSH

func ServeSSH(s SshServer) error

Takes an SshServer interface, performs setup, and calls the underlying type's serveSSH()

func SetWinsize

func SetWinsize(fd uintptr, w, h uint32)

SetWinsize sets the size of the given pty.

func SetupDefaultClientConfig

func SetupDefaultClientConfig() error

Sets up the default client configuration, including default private key and current user

func StartForwardedListener

func StartForwardedListener(conn *ssh.Client, url, remoteAddr string, port int, forwardFunc func(conn *ssh.Client, url string, port int) (stdin io.Writer, stdout io.Reader, stderr io.Reader, err error)) (chan bool, error)

Starts a forwarded listener by creating a server to listen on url

func StatRemoteFile

func StatRemoteFile(conn *ssh.Client, remoteOutPath string) ([]byte, error)

Gets the Stat information from a remote file

Types

type SshServer

type SshServer interface {
	// The PublicKeyCallback that will be used to verify and sign a public key
	PublicKeyCallback() func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error)
	// The PasswordCallback that will be used to verify a password login
	PasswordCallback() func(conn ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error)
	// The SSH Config the underlying type stores
	SshConfig() *ssh.ServerConfig
	// The default parsed private key for this server.
	Signer() (ssh.Signer, error)

	// The port to listen on
	Port() int
	// The network interface to listen on
	NetworkInterface() string
	// contains filtered or unexported methods
}

SshServer defines the methods required in order to implement an SSH Server

type Winsize

type Winsize struct {
	Height uint16
	Width  uint16
	// contains filtered or unexported fields
}

Winsize stores the Height and Width of a terminal.

Directories

Path Synopsis
GTN (or Go Tunnel) is an ssh tunneling program meant to transparently proxy a connection from a local machine to an ssh session, and then to connect to an arbitrary third host.
GTN (or Go Tunnel) is an ssh tunneling program meant to transparently proxy a connection from a local machine to an ssh session, and then to connect to an arbitrary third host.
RCURL (remote curl) creates an ssh session and then curls a remote host.
RCURL (remote curl) creates an ssh session and then curls a remote host.

Jump to

Keyboard shortcuts

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