curl-library
A question about using public key and private key for sftp authentication with libcurl
Date: Wed, 13 Oct 2010 14:01:54 +0800
Hi,
I'm using libcurl for sftp operations. But I find it strange that I have
to set both public key and private key in order to pass authentication.
I have a machine both as client and as server. That means it just
connects to itself. And the keys are deployed as below:
-------------------------
>pwd
/home/huangyal/.ssh
>ls
authorized_keys huangyalOAM_rsa.pub
huangyalOAM_rsa known_hosts
-------------------------
If I only set public key opt, libcurl output is like this:
-------------------------
* About to connect() to xxx.xxx.xxx.xxx port 22 (#0)
* Trying xxx.xxx.xxx.xxx... * connected
* Connected to xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx) port 22 (#0)
* SFTP 0x60420 state change from SSH_STOP to SSH_S_STARTUP
* SFTP 0x60420 state change from SSH_S_STARTUP to SSH_HOSTKEY
* SFTP 0x60420 state change from SSH_HOSTKEY to SSH_AUTHLIST
* SSH authentication methods available:
gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive
* SFTP 0x60420 state change from SSH_AUTHLIST to SSH_AUTH_PKEY_INIT
* Using ssh public key file /home/huangyal/.ssh/huangyalOAM_rsa.pub
* Using ssh private key file /home/huangyal/.ssh/id_dsa
* SFTP 0x60420 state change from SSH_AUTH_PKEY_INIT to SSH_AUTH_PKEY
* SSH public key authentication failed: Callback returned error
* SFTP 0x60420 state change from SSH_AUTH_PKEY to SSH_AUTH_PASS_INIT
* SFTP 0x60420 state change from SSH_AUTH_PASS_INIT to
SSH_AUTH_HOST_INIT
* SFTP 0x60420 state change from SSH_AUTH_HOST_INIT to SSH_AUTH_KEY_INIT
* SFTP 0x60420 state change from SSH_AUTH_KEY_INIT to SSH_AUTH_DONE
* Authentication failure
* SFTP 0x60420 state change from SSH_AUTH_DONE to SSH_SESSION_FREE
* SFTP 0x60420 state change from SSH_SESSION_FREE to SSH_STOP
* SSH DISCONNECT starts now
* SSH DISCONNECT is done
* Closing connection #0
* Login denied
-------------------------
And if I only set private key opt, libcurl output is like this:
-------------------------
* About to connect() to xxx.xxx.xxx.xxx port 22 (#0)
* Trying xxx.xxx.xxx.xxx... * connected
* Connected to xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx) port 22 (#0)
* SFTP 0x60420 state change from SSH_STOP to SSH_S_STARTUP
* SFTP 0x60420 state change from SSH_S_STARTUP to SSH_HOSTKEY
* SFTP 0x60420 state change from SSH_HOSTKEY to SSH_AUTHLIST
* SSH authentication methods available:
gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive
* SFTP 0x60420 state change from SSH_AUTHLIST to SSH_AUTH_PKEY_INIT
* Using ssh public key file /home/huangyal/.ssh/id_dsa.pub
* Using ssh private key file /home/huangyal/.ssh/huangyalOAM_rsa
* SFTP 0x60420 state change from SSH_AUTH_PKEY_INIT to SSH_AUTH_PKEY
* SSH public key authentication failed: Unable to open public key file
* SFTP 0x60420 state change from SSH_AUTH_PKEY to SSH_AUTH_PASS_INIT
* SFTP 0x60420 state change from SSH_AUTH_PASS_INIT to
SSH_AUTH_HOST_INIT
* SFTP 0x60420 state change from SSH_AUTH_HOST_INIT to SSH_AUTH_KEY_INIT
* SFTP 0x60420 state change from SSH_AUTH_KEY_INIT to SSH_AUTH_DONE
* Authentication failure
* SFTP 0x60420 state change from SSH_AUTH_DONE to SSH_SESSION_FREE
* SFTP 0x60420 state change from SSH_SESSION_FREE to SSH_STOP
* SSH DISCONNECT starts now
* SSH DISCONNECT is done
* Closing connection #0
* Login denied
-------------------------
It seems that if I only set public key, libcurl will invoke some
callback. I don't set any callback in my code. Could it be the reason of
this problem?
Besides, could you tell me where I can get some example code for sftp
operations. I think that will be a great help, since I don't even know
how to write a callback for sftp. Thank you.
Regards
Lin Huangyang
8477-7571
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-10-13