我正在编写一个Groovy脚本来做一个SCP。 请注意,我还没有运行它,因为其余的没有完成。 现在,如果你第一次做一个scp,必须authentication指纹。 未来的时代,你不会。
我目前的解决scheme是,因为我得到了三次密码,而且我真的只需要一次(不是脚本会输错密码,如果错了,这是错误的!第一次密码尝试。 这样,它将接受指纹,如果有必要,并使用正确的密码作为第一次尝试。 如果不需要它,那么第一次就是肯定的,第二次是正确的。
但是,我觉得这不是一个非常强大的解决scheme,我知道如果我是一个客户,我不希望在输出中看到“不正确的密码”。 特别是如果因为另一个原因失败了,这将是一个令人难以置信的令人讨厌的用词不当。
以下是有关脚本的相应部分。 我愿意以任何不同的方式使用scp(或者完成文件传输)。 我只想完成工作。 我甚至打开shell脚本,虽然我不是最好的。
def command = [] command.add('scp') command.add(srcusername + '@' + srcrepo + ':' + srcpath) command.add(tarusername + '@' + tarrepo + ':' + tarpath) def process = command.execute() process.consumeOutput(out) process << "yes" << LS << tarpassword << LS process << "yes" << LS << srcpassword << LS process.waitfor()
非常感谢,
glowcoder
man ssh_config
“… StrictHostKeyChecking如果这个标志被设置为yes'', ssh(1) will never automatically add host keys to the ~/.ssh/known_hosts file, and refuses to connect to hosts whose host key has changed. This provides maximum protection against trojan horse attacks, though it can be annoying when the /etc/ssh/ssh_known_hosts file is poorly main‐ tained or when connections to new hosts are frequently made. This option forces the user to manually add all new hosts. If this flag is set to ssh会自动添加新的主机密钥到用户已知的主机文件,如果这个标志设置为ask'', new host keys will be added to the user known host files only after the user has confirmed that is what they really want to do, and ssh will refuse to connect to hosts whose host key has changed. The host keys of known hosts will be verified automatically in all cases. The argument must be yes, no'', or '' ,默认为“ask”' …“
可悲的不安全的答案: http : //linuxcommando.blogspot.com/2008/10/how-to-disable-ssh-host-key-checking.html
(基本上提供了ssh命令选项指令,使它看起来在/dev/null的主机密钥,并忽略事实,它从来没有见过的关键之前 – 解决了这个问题,但抛弃了任何安全防范措施,让你打开密码或私钥收获攻击)
为什么不写一个基本上执行ssh-keyscan的ssh封装,然后检查〜/ .ssh / known_hosts中是否存在hostkey? 如果它不在known_hosts中,那么期待是的。