viant / afs

Abstract File Storage
Apache License 2.0
297 stars 34 forks source link

How to specify remote scp username #8

Closed wmccracken closed 3 years ago

wmccracken commented 3 years ago

Hello,

I was wondering how to specify the username of the remote user when using scp with LocalhostKeyAuth. It appears to try and connect as the user that is running the program (USER from env). I tried modifying the url to scp://user@host:22/path/to/file but that does not work.

Thanks!

-Will

adranwit commented 3 years ago

Credenitals are supplied as options, to use user/passwor use the following:

auth := scp.NewAuthProvider(nil, option.NewBasicAuth("myuser", "password")) data, err := fs.DownloadWithURL(context.Background(), "scp://127.0.0.1/etc/hosts", auth)

wmccracken commented 3 years ago

How would this work with ssh keys instead of basic auth?

Sent from my iPhone

On Feb 6, 2021, at 7:41 PM, adranwit notifications@github.com wrote:



Credenitals are supplied as options, to user user/passwor dyou the use the following:

auth := scp.NewAuthProvider(nil, option.NewBasicAuth("myuser", "password")) data, err := fs.DownloadWithURL(context.Background(), "scp://127.0.0.1/etc/hosts", auth)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/viant/afs/issues/8#issuecomment-774567090, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAAX3ZXPH2BVBQ6YNCAHR43S5XORPANCNFSM4XGK7WKA.

adranwit commented 3 years ago

auth := scp.NewAuthProvider(nil, option.NewBasicAuth("myuser", "password")) this should use only basic auth, thus no ssh keys are needed,

adranwit commented 3 years ago

SSH auth supported methods:

https://github.com/viant/afs/blob/master/scp/auth.go

adranwit commented 3 years ago
auth := scp.NewAuthProvider(scp.NewKeyAuth(path.Join(os.Getenv("HOME"), ".ssh", "id_rsa"), "myuser", "optional_password_for_pem_file_leave_empty_otherwise"), nil)
data, err := fs.DownloadWithURL(context.Background(), "scp://127.0.0.1/etc/hosts", auth)
wmccracken commented 3 years ago

Thank you!