SFTP connectivity and docs improvements (#623)

* sftp: support for external SSH command and host verfication improvements

- removed custom parsing of hostnames and verification and replaced with
  standard 'knownhosts' implementation.

- added option to launch external SSH command which supports
  aliases, agent, etc.

NOTE, we're still not supporting any cases where password needs to be
entered on the command line, since that would be incompatible with
the UI which uses client-server model.

Fixes #500
Fixes #414

* site: updated SFTP repository connection instructions

Fixes #590
This commit is contained in:
Jarek Kowalski authored and GitHub committed 2020-09-20 11:10:13 -07:00
1 parent 0595213d79
commit d0d6ac4767
8 files changed
+271 -107

No files matched your search

+25 -18
View File
@@ -31,36 +31,43 @@ func init() {
cmd.Flag("known-hosts", "path to known_hosts file").StringVar(&options.KnownHostsFile)
cmd.Flag("known-hosts-data", "known_hosts file entries").StringVar(&options.KnownHostsData)
cmd.Flag("embed-credentials", "Embed key and known_hosts in Kopia configuration").BoolVar(&embedCredentials)
cmd.Flag("external", "Launch external passwordless SSH command").BoolVar(&options.ExternalSSH)
cmd.Flag("ssh-command", "SSH command").Default("ssh").StringVar(&options.SSHCommand)
cmd.Flag("ssh-args", "Arguments to external SSH command").StringVar(&options.SSHArguments)
cmd.Flag("flat", "Use flat directory structure").BoolVar(&connectFlat)
},
func(ctx context.Context, isNew bool) (blob.Storage, error) {
sftpo := options
// nolint:nestif
if embedCredentials {
if sftpo.KeyData == "" {
d, err := ioutil.ReadFile(sftpo.Keyfile)
if err != nil {
return nil, err
if !sftpo.ExternalSSH {
if embedCredentials {
if sftpo.KeyData == "" {
d, err := ioutil.ReadFile(sftpo.Keyfile)
if err != nil {
return nil, err
}
sftpo.KeyData = string(d)
sftpo.Keyfile = ""
}
sftpo.KeyData = string(d)
sftpo.Keyfile = ""
}
if sftpo.KnownHostsData == "" && sftpo.KnownHostsFile != "" {
d, err := ioutil.ReadFile(sftpo.KnownHostsFile)
if err != nil {
return nil, err
}
if sftpo.KnownHostsData == "" && sftpo.KnownHostsFile != "" {
d, err := ioutil.ReadFile(sftpo.KnownHostsFile)
if err != nil {
return nil, err
sftpo.KnownHostsData = string(d)
sftpo.KnownHostsFile = ""
}
sftpo.KnownHostsData = string(d)
sftpo.KnownHostsFile = ""
}
}
if sftpo.KeyData == "" && sftpo.Keyfile == "" {
return nil, errors.Errorf("must provide either key file or key data")
if sftpo.KeyData == "" && sftpo.Keyfile == "" {
return nil, errors.Errorf("must provide either key file or key data")
}
}
if connectFlat {