在python中使用fabric连接到主机时,会得到一个提示(“root”的登录密码):)询问root密码

2024-06-07 17:23:22 发布

您现在位置:Python中文网/ 问答频道 /正文

在python中,文件代码如下: 带设置(host_string=elasticIP,key_filename='/path/to/密钥文件.pem,user='root',使用_ssh_config=False): 运行(“任意命令”)

执行此操作后,控制台中会出现一个提示,说明“root用户的登录密码:”,因为我们没有这个用户“root”的密码,所以我们不确定要提供什么密码,但是,在控制台中随机给出任何文本作为“root”的密码,它接受并进一步移动。在

当我们使用nohup在后台运行同一个python程序时,有时会出现相同的提示,有时甚至不会出现。在

我们正在处理eucalyptus实例,希望环境不是这里的问题。 请建议。。。在


Tags: 文件topathkey代码用户host密码
2条回答

使用settings时,不要使用run,使用execute。在

from fabric.decorators import task
from fabric.operations import run, execute

def my_command():
    run('echo "hello fabric!"')

@task
def my_task():
    with settings(host_string=elasticIP, key_filename = '/path/to/keyfile.pem', user = 'root', use_ssh_config = False):
        execute(my_command)

我深入研究了这个问题,最后得到了答案: 文件:/etc/ssh/ssh\u config 包含属性“UserKnownHostsFile”和“StrictHostKeyChecking” 这些属性应描述为: StrictHostKeyChecking否 UserKnownHostsFile=/dev/null UserKnownHostsFile定义了ssh和与特定机器相关的一些元数据的存储。如果这些细节不匹配,它会要求您确认该机器是否正确。 所以做出这些改变,一切顺利。 参考文献: http://linuxcommando.blogspot.in/2008/10/how-to-disable-ssh-host-key-checking.html

以及

https://superuser.com/questions/19563/how-do-i-skip-the-known-host-question-the-first-time-i-connect-to-a-machine-vi

相关问题 更多 >

    热门问题