sftp 和公钥

Liz*_*ard 5 ssh sftp public-key-encryption

我正在尝试将 sftp 连接到由其他人托管的服务器。

为了确保这sftp user@sftp.xxxxxx.com行得通,我做了标准,我被提示输入密码并且工作正常。

我正在设置一个 cron 脚本来每周发送一次文件,因此给了他们我们的公钥,他们声称已将其添加到他们的 authorized_keys 文件中。

我现在再试sftp user@sftp.xxxxxx.com一次,仍然提示我输入密码,但现在密码不起作用...

Connecting to user@sftp.xxxxxx.com...
user@sftp.xxxxxx.com's password: 
Permission denied, please try again.
user@sftp.xxxxxx.com's password: 
Permission denied, please try again.
user@sftp.xxxxxx.com's password: 
Permission denied (publickey,password).
Couldn't read packet: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)

但是,我确实注意到,如果我只是按下enter(无密码),它会很好地登录我......

所以这里是我的问题:

  1. 有没有办法检查我的 sftp 连接使用的是哪个私钥/公钥对?
  2. 是否可以指定要使用的密钥对?
  3. 如果所有设置都正确(使用正确的密钥对并添加到授权文件中),为什么会要求我输入空白密码?

提前感谢您的帮助!

更新

我刚跑 sftp -vvv user@sftp.xxxxxx.com

....
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /root/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug2: input_userauth_pk_ok: SHA1 fp 45:1b:e7:b6:33:41:1c:bb:0f:e3:c1:0f:1b:b0:d5:e4:28:a3:3f:0e
debug3: sign_and_send_pubkey
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
Run Code Online (Sandbox Code Playgroud)

似乎表明它尝试使用公钥......我错过了什么?

小智 3

在详细模式下运行应该可以帮助您:

sftp -vvv user@sftp.xxxxxx.com
Run Code Online (Sandbox Code Playgroud)

这将向您显示它正在使用哪些密钥,以及为什么它要求输入密码。

更新:您可以告诉 ssh 使用哪个私钥:http://www.cyberciti.biz/faq/force-ssh-client-to-use-given-private-key-identity-file/但我不确定您会如何做同样的服务器端