Documentation
¶
Overview ¶
Package ssh implements various SSH commands.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Logger *zap.Logger
KeyPath string
PublicIP string
PublicDNSName string
// UserName is the user name to use for log-in.
// "ec2-user" for Amazon Linux 2
// "ubuntu" for ubuntu
UserName string
// Envs is the set of environmental variables to use
// in the SSH session.
Envs map[string]string
}
Config defines SSH configuration.
type Op ¶
type Op struct {
// contains filtered or unexported fields
}
Op represents a SSH operation.
type OpOption ¶
type OpOption func(*Op)
OpOption configures archiver operations.
func WithEnv ¶
WithEnv adds an environment variable that will be applied to any command executed by Shell or Run. It overwrites the ones set by "*ssh.Session.Setenv".
func WithRetry ¶
WithRetry automatically retries the command on closed TCP connection error. (e.g. retry immutable operation). WithRetry(-1) to retry forever until success. e.g. "read tcp 10.119.223.210:58688->54.184.39.156:22: read: connection timed out"
func WithTimeout ¶
WithTimeout configures timeout for command run.
func WithVerbose ¶
WithVerbose configures verbose level in SSH operations.
type SSH ¶
type SSH interface {
// Connect connects to a remote server creating a new client session.
// "Close" must be called after use.
Connect() error
// Close closes the session and connection to a remote server.
Close()
// Run runs the command and returns the output.
Run(cmd string, opts ...OpOption) (out []byte, err error)
// Send sends a file to the remote host using SCP protocol.
Send(localPath, remotePath string, opts ...OpOption) (out []byte, err error)
// Download downloads a file from the remote host using SCP protocol.
Download(remotePath, localPath string, opts ...OpOption) (out []byte, err error)
}
SSH defines SSH operations. For example, automates the following:
ssh -o "StrictHostKeyChecking no" \ -i ./aws-k8s-tester-ec2.key669686897 \ ec2-user@ec2-35-166-71-150.us-west-2.compute.amazonaws.com rm -f ./text.txt echo "Hello" > ./text.txt scp -oStrictHostKeyChecking=no \ -i ./aws-k8s-tester-ec2.key301005900 \ ./text.txt \ ec2-user@ec2-35-166-71-150.us-west-2.compute.amazonaws.com:/home/ec2-user/test.txt scp -oStrictHostKeyChecking=no \ -i ./aws-k8s-tester-ec2.key301005900 \ ./testfile449686843 \ ec2-user@34.220.64.30:22:/home/ec2-user/aws-k8s-tester.txt scp -oStrictHostKeyChecking=no \ -i ./aws-k8s-tester-ec2.key301005900 \ ec2-user@ec2-35-166-71-150.us-west-2.compute.amazonaws.com:/home/ec2-user/test.txt \ ./test2.txt