Documentation
¶
Index ¶
- func NewSSHClient(cfg *Config) (*ssh.Client, error)
- type Client
- type ClientOptions
- type Config
- func (cfg *Config) Addr() string
- func (cfg *Config) AskPassword() bool
- func (cfg *Config) DockerHost() string
- func (cfg *Config) Host() string
- func (cfg *Config) OpenIdentityFile() (*os.File, error)
- func (cfg *Config) Port() string
- func (cfg *Config) SSHDir() string
- func (cfg *Config) Username() string
- type LogSeq
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSSHClient ¶
NewSSHClient creates a new SSH client for the given host, username, and identity file.
The host can be in the format of "example.com", "user@example.com:22", or any valid combination of username, hostname, and port. If the port is not specified, it defaults to 22.
If a ~/.ssh/config file is present and contains an entry matching host, username, port or identity file, the values from the config will override the corresponding values provided by the command line arguments.
If a username is provided, the client will use password authentication. If the username is provided in both the host string and the argument, it will return an error.
If no username is provided, it will try to use an identity file for authentication.
If the identity file is provided, it will be used. Any identity file outside of ~/.ssh will not be accepted for security reasons. Otherwise, the default identity files in the .ssh directory will be tried, e.g., id_ed25519, id_rsa, and id_ecdsa.
In either case, the client will check the host key against the known_hosts file in the ~/.ssh directory.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func New ¶
func New(cOpts ...ClientOptions) (*Client, error)
func (*Client) DaemonHost ¶
func (*Client) DaemonVersion ¶
type ClientOptions ¶
type ClientOptions func(*Config)
func WithAskPassword ¶
func WithAskPassword(ask bool) ClientOptions
func WithDockerHost ¶
func WithDockerHost(host string) ClientOptions
func WithHost ¶
func WithHost(host string) ClientOptions
func WithIdentityFile ¶
func WithIdentityFile(identityFile string) ClientOptions
func WithUsername ¶
func WithUsername(username string) ClientOptions
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func NewConfig ¶
func NewConfig(opts ...ClientOptions) (*Config, error)
NewSSHClient creates a new SSH client for the given optins.
Note that the host, username, port and identity file can be rewritten during ssh client construction with the value provided in the ~/.ssh/config file.
Use the method of the client to get the constructed Addr, Host, Port, Username, AskPassword, SSHDir and DockerSocket.
func (*Config) AskPassword ¶
func (*Config) DockerHost ¶
func (*Config) OpenIdentityFile ¶
openIdentityFile tries to open the identity file from the given filename or if filename is empty, the ~/.ssh/config is parsed and cfg.host, cfg.username and cfg.identityFile is rewritten. If ~/.ssh/config is not present, the default ones in the ~/.ssh directory are used, e.g., id_ed25519, id_rsa, and id_ecdsa.
In either case, the file must be inside the ~/.ssh directory. Any file outside of it will not be accepted for security reasons.
The caller is responsible for closing the file.
It returns an error if the file cannot be opened or if the filename is outside of the ~/.ssh directory.