添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
){outline:none;box-shadow:none;}select::-ms-expand{;}:root,:host{--chakra-vh:100vh;}@supports (height: -webkit-fill-available){:root,:host{--chakra-vh:-webkit-fill-available;}}@supports (height: -moz-fill-available){:root,:host{--chakra-vh:-moz-fill-available;}}@supports (height: 100dvh){:root,:host{--chakra-vh:100dvh;}}
Avatar of Michael Lam
Michael Lam

asked on

cURL SFTP with private key

i am running curl on windows 7, and would like see if as opposed to username/pwd i can just use a private key for authentication.  can someone show me how to do this?
i tried doing this:
1) use cygwin to do ssh-keygen -t rsa
$ ssh server "mkdir .ssh; chmod 0700 .ssh"
$ scp .ssh/id_rsa.pub server:.ssh/authorized_key s2
2) C:\Users\mlam\Downloads\Cu rl>curl --key C:\cygwin\home\mlam\.ssh\i d_rsa -T c:\temp2\test4.txt s ftp://servername/var/SFTP/test9.txt --insecure
but i got this:  curl: (67) Authentication failure
can someone help me?  also, is it more common to use username/password or to use private key for authentication?  thanks. Didn't you forget to use "-u username"? You still need to select the right username unless your windows username equals the unix username. (normaly cygwin does this mapping for you, but you seem to run curl without cygwin).
Check the auth log on your server to see what failed.
The authlog mostly is in /var/log/auth (YMMV, depending on configuration/syslog logger used).
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
curl -u username:password --key C:\cygwin\home\mlam\.ssh\i d_rsa --pubkey c:\cygwin\home\mlam\i
d_dsa.pub -T c:\temp2\test4.txt s ftp://servername/var/SFTP/test9.txt --insecure
this is the only way i got it to work, which kind of defeats the purpose of having a key pair since i also put in username and password. the :password should not be needed.... (That's the whole pupose of certificates. But the username is needed to signal the remote WHAT directory (based on username) to search for the public user certificate. BTW, I have no windows system myself so i can't test the setup exqctly. On unix systems ssh & friends use the current user as default (as does cygwin).
i tried to use private key as password, but for some reason cURL is not using it.
C:\Users\mlam\Downloads\Cu rl>curl -u mlam --key ~/.ssh/id_rsa -T c:\temp2\test4.txt s ftp://server/var/SFTP/ --insecure
Enter host password for user 'mlam':
i also tried:
C:\Users\mlam\Downloads\Cu rl>curl -u mlam --key c:\...\.ssh\id_rsa -T c:\temp2\test4.txt s ftp://server/var/SFTP/ --insecure