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
- Variables
- func Copy(conn *ssh.Client, filename, destinationPath string, data []byte) error
- func CopyFile(filePath, destinationPath string, conn *ssh.Client) error
- func CopyWithFileMode(mode os.FileMode, filename, destinationPath string, data []byte, ...) error
- func CurlFromRemote(conn *ssh.Client, url string, args ...string) ([]byte, error)
- func DefaultSshHandler(s SshServer)
- func DoesRemoteFileExist(conn *ssh.Client, filepath string) bool
- func Forward(conn *ssh.Client, listener net.Listener, url string, port int, ret chan bool, ...) error
- func ForwardNetcat(conn *ssh.Client, url string, port int) (stdin io.Writer, stdout io.Reader, stderr io.Reader, err error)
- func GetRemoteFile(path string, conn *ssh.Client) (data []byte, filename string, err error)
- func GetSshConn(url string, config *ssh.ClientConfig) (*ssh.Client, error)
- func MakeRemoteDir(conn *ssh.Client, dirname string) error
- func ParsePrivateKey(keyPath string) (ssh.AuthMethod, error)
- func RemoveRemoteDir(conn *ssh.Client, dirname string) error
- func RemoveRemoteFile(conn *ssh.Client, filepath string) error
- func ServeSSH(s SshServer) error
- func SetWinsize(fd uintptr, w, h uint32)
- func SetupDefaultClientConfig() error
- func StartForwardedListener(conn *ssh.Client, url, remoteAddr string, port int, ...) (chan bool, error)
- func StatRemoteFile(conn *ssh.Client, remoteOutPath string) ([]byte, error)
- type SshServer
- type Winsize
Constants ¶
const ( DefaultPort = 2222 DefaultNetworkInterface = "0.0.0.0" )
Variables ¶
var ( CurrentUser string DefaultClientConfig *ssh.ClientConfig )
var ( FileNotFound = errors.New("No such file or directory") FileExists = errors.New("File or directory already exists") )
errors
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
var (
DefaultServer = newDefaultServer()
)
Functions ¶
func CopyFile ¶
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 ¶
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 ¶
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 ¶
Retrieves a remote file very inefficiently. This can be done better
func GetSshConn ¶
Returns an SSH connection with the given config and url
func MakeRemoteDir ¶
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 ¶
Remotes a remote directory
func RemoveRemoteFile ¶
Removes a remote file
func ServeSSH ¶
Takes an SshServer interface, performs setup, and calls the underlying type's serveSSH()
func SetWinsize ¶
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
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
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. |