Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

Fix ssh agent on Windows - fixes #1279

Nick Craig-Wood5455d34f8c7c
diff --git a/docs/content/sftp.md b/docs/content/sftp.md
index f2552ab98..d173705d2 100644
--- a/docs/content/sftp.md
+++ b/docs/content/sftp.md
@@ -121,6 +121,8 @@ Modified times are used in syncing and are fully supported.
SFTP does not support any checksums.
+The only ssh agent supported under Windows is Putty's pagent.
+
SFTP isn't supported under plan9 until [this
issue](https://github.com/pkg/sftp/issues/156) is fixed.
diff --git a/sftp/sftp.go b/sftp/sftp.go
index d52878d37..e2bc7d1c0 100644
--- a/sftp/sftp.go
+++ b/sftp/sftp.go
@@ -6,7 +6,6 @@ package sftp
import (
"io"
- "net"
"os"
"path"
"sync"
@@ -15,8 +14,8 @@ import (
"github.com/ncw/rclone/fs"
"github.com/pkg/errors"
"github.com/pkg/sftp"
+ sshagent "github.com/xanzy/ssh-agent"
"golang.org/x/crypto/ssh"
- "golang.org/x/crypto/ssh/agent"
)
func init() {
@@ -94,15 +93,10 @@ func NewFs(name, root string) (fs.Fs, error) {
Timeout: fs.Config.ConnectTimeout,
}
if pass == "" {
- authSock := os.Getenv("SSH_AUTH_SOCK")
- if authSock == "" {
- return nil, errors.New("SSH_AUTH_SOCK is unset so can't connect to ssh-agent")
- }
- sshAgent, err := net.Dial("unix", authSock)
+ sshAgentClient, _, err := sshagent.New()
if err != nil {
return nil, errors.Wrap(err, "couldn't connect to ssh-agent")
}
- sshAgentClient := agent.NewClient(sshAgent)
signers, err := sshAgentClient.Signers()
if err != nil {
return nil, errors.Wrap(err, "couldn't read ssh agent signers")