sftp和公钥

我正在尝试进入由其他人托pipe的服务器。

为了确保这个工作,我做了标准的sftp [email protected]我与密码,并认为工作正常。

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

我现在再次尝试sftp [email protected] ,我仍然提示input密码,但现在密码不起作用…

 Connecting to [email protected]... [email protected]'s password: Permission denied, please try again. [email protected]'s password: Permission denied, please try again. [email protected]'s password: Permission denied (publickey,password). Couldn't read packet: Connection reset by peer 

但我注意到,如果我只是按下enter (没有密码),它logging了我的罚款…

所以这是我的问题:

  1. 有没有办法来检查我的sftp连接使用的是哪个privatekey / pulbickey对?
  2. 是否可以指定要使用的密钥对?
  3. 如果全部设置正确(使用正确的密钥对并添加到授权文件中)为什么我被要求input一个空密码?

感谢您的帮助提前!

更新我刚刚运行sftp -vvv [email protected]

 .... 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 

它似乎表明,它试图使用公钥…我错过了什么?

debug3:尝试私钥:/root/.ssh/id_dsa

debug3:没有这样的标识:/root/.ssh/id_dsa

您是否以root用户身份创build密钥对? 看起来不像你这样做,因为/root/.ssh/id_dsa似乎不存在(或者权限可能是错误的:只能被root用户读/写;没有世界/组的读/写权限)。

编辑

看起来你已经通过你的ls的外观生成了rsa键,但是你提供了dsa键。

你是说你可以使用空的root密码login吗? 我会高度考虑审查这一点,并确保帐户没有受到损害。

 ls -l /root/.ssh/id_dsa 

应该返回

 -rw------- root ... 

打开一个新的terminal,在其他端口上以debugging模式(-d选项)运行sshd。 debugging模式只适用于使用完整path。 所以

 `which sshd` -d -p 9999 

观察该控制台的标准输出并再次尝试sftp

 sftp -oPort=9999 [email protected] 

检查输出,如果你不知道发生了什么,粘贴到这里。

SSH是非常严格的权限。 另外,你怎么指定的关键? 你让ssh尝试〜/ .ssh / id_rsa的默认值?

请尝试使用以下命令在CLI中指定密钥:-oIdentityFile = / root / .ssh / id_rsa

如果你有权限访问服务器,检查auth.log,你可以找出为什么它拒绝密钥…但有趣的是,服务器似乎接受一个关键。