本文介绍了Python Fabric:跳过需要密码的登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与此类似的问题:如何跳过要求连接的Fabric连接密码?没有答案.我正在寻找一种方法,使Fabric认为任何要求密码而不是SSH密钥登录的主机都是错误的,因为这意味着我要连接的用户在服务器上没有帐户(而我遍历大量主机).我尝试设置

I have a similar issue to this:How can I skip Fabric connections that ask for a password?which has no answer. I'm looking for a way to get Fabric to consider bad any host asking for a password instead of an SSH key login, since this means the user I'm connecting as doesn't have an account on the server (and I'm iterating through a large list of hosts). I've tried setting

env.password = None

env.password = 'none'

以及

with setting(warn_only=True):

,但是Fabric不断询问密码.可以解决这个问题吗?

but Fabric keeps asking for the password. Any way around this?

推荐答案

我相信 env.abort_on_prompts 将实现您所需要的功能,即在需要公钥身份验证的情况下,如果需要任何类型的用户交互都将失败.

I believe env.abort_on_prompts will achieve what you need, i.e. fail if there is a need for any kind of user interaction, while working when public key authentication is possible.

根据文档,此选项调用 abort()依次使用 sys.exit ,它会引发 SystemExit ,从而可以检测并从中恢复使用except SystemExit或类似方法对abort进行内部调用.

According to the documentation, this option calls abort() which in turn make use of sys.exit, which raises SystemExit making it possible to detect and recover from inner calls to abort by using except SystemExit or similar.

这篇关于Python Fabric:跳过需要密码的登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 05:27