Documentation ¶
Overview ¶
Package ssh is a helper for working with ssh in go. The client implementation is a modified version of `docker/machine/libmachine/ssh/client.go` and only uses golang's native ssh client. It has also been improved to resize the tty accordingly. The key functions are meant to be used by either client or server and will generate/store keys if not found.
Index ¶
- func GenKeyPair() (string, string, error)
- func GetKeyPair(file string) (string, string, error)
- func NewNativeConfig(user, clientVersion string, auth *Auth, hostKeyCallback ssh.HostKeyCallback) (ssh.ClientConfig, error)
- type Auth
- type Client
- type Config
- type ExitError
- type NativeClient
- func (client *NativeClient) Output(command string) (string, error)
- func (client *NativeClient) OutputWithPty(command string) (string, error)
- func (client *NativeClient) Shell(args ...string) error
- func (client *NativeClient) Start(command string) (io.ReadCloser, io.ReadCloser, error)
- func (client *NativeClient) Wait() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenKeyPair ¶
GenKeyPair make a pair of public and private keys for SSH access. Public key is encoded in the format for inclusion in an OpenSSH authorized_keys file. Private Key generated is PEM encoded
func GetKeyPair ¶
GetKeyPair will attempt to get the keypair from a file and will fail back to generating a new set and saving it to the file. Returns pub, priv, err
func NewNativeConfig ¶
func NewNativeConfig(user, clientVersion string, auth *Auth, hostKeyCallback ssh.HostKeyCallback) (ssh.ClientConfig, error)
NewNativeConfig returns a golang ssh client config struct for use by the NativeClient
Types ¶
type Auth ¶
type Auth struct { Passwords []string // Passwords is a slice of passwords to submit to the server Keys []string // Keys is a slice of filenames of keys to try RawKeys [][]byte // RawKeys is a slice of private keys to try }
Auth contains auth info
type Client ¶
type Client interface { // Output returns the output of the command run on the remote host. Output(command string) (string, error) // Shell requests a shell from the remote. If an arg is passed, it tries to // exec them on the server. Shell(args ...string) error // Start starts the specified command without waiting for it to finish. You // have to call the Wait function for that. // // The first two io.ReadCloser are the standard output and the standard // error of the executing command respectively. The returned error follows // the same logic as in the exec.Cmd.Start function. Start(command string) (io.ReadCloser, io.ReadCloser, error) // Wait waits for the command started by the Start function to exit. The // returned error follows the same logic as in the exec.Cmd.Wait function. Wait() error }
Client is a relic interface that both native and external client matched
type Config ¶
type Config struct { User string // username to connect as, required Host string // hostname to connect to, required Version string // ssh client version, "SSH-2.0-Go" by default Port int // port to connect to, 22 by default Auth *Auth // authentication methods to use Timeout time.Duration // connect timeout, 30s by default HostKey ssh.HostKeyCallback // callback for verifying server keys, ssh.InsecureIgnoreHostKey by default }
Config is used to create new client.
type ExitError ¶
ExitError is a conveniance wrapper for (crypto/ssh).ExitError type.
type NativeClient ¶
type NativeClient struct { Config ssh.ClientConfig // Config defines the golang ssh client config Hostname string // Hostname is the host to connect to Port int // Port is the port to connect to ClientVersion string // ClientVersion is the version string to send to the server when identifying // contains filtered or unexported fields }
NativeClient is the structure for native client use
func (*NativeClient) Output ¶
func (client *NativeClient) Output(command string) (string, error)
Output returns the output of the command run on the remote host.
func (*NativeClient) OutputWithPty ¶
func (client *NativeClient) OutputWithPty(command string) (string, error)
Output returns the output of the command run on the remote host as well as a pty.
func (*NativeClient) Shell ¶
func (client *NativeClient) Shell(args ...string) error
Shell requests a shell from the remote. If an arg is passed, it tries to exec them on the server.
func (*NativeClient) Start ¶
func (client *NativeClient) Start(command string) (io.ReadCloser, io.ReadCloser, error)
Start starts the specified command without waiting for it to finish. You have to call the Wait function for that.
func (*NativeClient) Wait ¶
func (client *NativeClient) Wait() error
Wait waits for the command started by the Start function to exit. The returned error follows the same logic as in the exec.Cmd.Wait function.