我有点困惑,我已经build立了两台服务器之间的公钥,它工作得很好,有点。 它只适用于我手动从terminalssh。 当我把ssh命令放到一个python脚本中时,它会要求我input一个密码来login。 该脚本使用rsync来同步从一台服务器到另一台的目录。
手动ssh命令即可,无密码提示,自动login:
ssh -p 1234 [email protected]
在Python脚本中:
rsync --ignore-existing --delete --stats --progress -rp -e "ssh -p 1234" [email protected]:/directory/ /other/directory/
是什么赋予了?
(显然,ssh的细节都是假的)
每个请求编辑
@Zoredache – 我在脚本中放了-vv (和-i指定键的位置,实际上让我更靠近了一步),它显示了一堆有趣的线条:
debug1: Host '[123.456.789.123]:1234' is known and matches the RSA host key. debug1: Found key in /root/.ssh/known_hosts:1 debug2: bits set: 515/1024 debug1: ssh_rsa_verify: signature correct debug2: kex_derive_keys debug2: set_newkeys: mode 1 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug2: set_newkeys: mode 0 debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug2: key: /home/garfonzo/.ssh/id_dsa.pub (0x7f125c489bd0) debug1: Authentications that can continue: publickey,password debug1: Next authentication method: publickey debug1: Offering public key: /home/garfonzo/.ssh/id_dsa.pub debug2: we sent a publickey packet, wait for reply debug1: Server accepts key: pkalg ssh-dss blen 434 debug2: input_userauth_pk_ok: fp 81:02:20:f0:62:16:30:15:4d:0b:2e:91:7c:ba:5c:05 debug1: PEM_read_PrivateKey failed debug1: read PEM private key done: type <unknown> Enter passphrase for key '/home/garfonzo/.ssh/id_dsa.pub': debug2: no passphrase given, try next key debug2: we did not send a packet, disable method debug1: Next authentication method: password
它似乎并不知道我的密钥存储在客户端(可能是之前的问题),它是要求密码。 问题是我没有指定密码,我把它留空。 奇怪的…也许我会创build一组新的密钥?
编辑2
@ckliborn – 好主意! 我想这可能表明我的问题是什么。 我认为我指出的一个问题是:
debug1: Found key in /home/garfonzo/.ssh/known_hosts:1
而当通过脚本运行时,同一行是:
debug1: Found key in /root/.ssh/known_hosts:1
所以,客户正在寻找关键的错误位置。 当我指定密钥的位置时,它会要求input一个密码,我没有设置。 精氨酸!
?困惑?
在python脚本中,您是否曾尝试明确给出您想使用“-i”标志的身份文件的位置?
例如:
rsync –ignore-existing –delete –stats –progress -rp -e“ssh -i /home/user/.ssh/keyfile -p 1234”[email protected]
尝试添加一个新的主机到你的〜/ .ssh / config文件,确保修改:
Host somehostname Hostname 169.1.1.254 User garfonzo IdentityFile /home/garfonzo/.ssh/id_rsa PubkeyAuthentication yes
如果你的密钥有一个密码,并且它应该,你需要来源〜/ ssh-agent。
http://www.ibm.com/developerworks/library/l-keyc2/
如果您已经省略了密钥的密码,请按照上面的提示并传入“-i”参数。
你的python脚本是用#!/usr/bin/env python还是直接执行#!/usr/bin/python或类似的命令。 此外,您可以尝试删除-e "ssh -p 1234"而只是使用--port 1234 。
检查你的用户…脚本似乎以root身份运行,而你的testing是以用户的身份完成的。 您是使用su还是sudo或者您是以root身份login? 你的脚本如何开始? 它以某种方式拥有root权限吗?