ansible报错Using a SSH password instead of a key is not possible because Host Key checking is enabled ...

本文介绍了解决Ansible在使用过程中遇到的一个常见错误:当尝试通过密码而非密钥进行SSH连接时,由于启用了HostKey检查而无法完成操作。文中提供了一种修改Ansible配置文件的方法来禁用HostKey检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装和配置好ansible,执行命令时报错如下

[root@test01 ansible-install]# ansible test -m shell -a 'w'
10.xx.37.26 | FAILED | rc=-1 >>
Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host.

10.xx.37.25 | FAILED | rc=-1 >>
Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host.

10.xx.37.24 | FAILED | rc=-1 >>
Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host.

 

解决方法:

vi /etc/ansible/ansible.cfg
[defaults]
forks          = 8           #执行时并发数
host_key_checking = False    #不检测host key

 

当使用Ansible时,可能会遇到这样的错误提示:“added 'ip' (ecdsa) to the list of known hosts”。这个错误提示表示Ansible试图将目标主机的IP地址添加到已知主机列表中。 这个错误通常是由于第一次连接到远程主机时引起的,Ansible将主机密钥添加到~/.ssh/known_hosts文件中。这是Ansible的正常行为,以确保安全连接和身份验证。 要解决这个问题,有以下几种方法: 1. 忽略已知主机检查:在执行Ansible命令时,可以使用`-k`参数或`--ask-pass`参数来忽略对已知主机的检查。例如,`ansible-playbook -i inventory.ini playbook.yaml -k`。这个方法虽然简单,但会牺牲一部分安全性。 2. 更新known_hosts文件:如果你确定目标主机是安全的,你可以手动更新`~/.ssh/known_hosts`文件,添加目标主机的IP地址和密钥。你可以使用SSH命令`ssh-keyscan`来获取主机密钥并添加到known_hosts文件中。例如,`ssh-keyscan -H ip >> ~/.ssh/known_hosts`。这样做的好处是避免了每次连接时的询问,但仍保持了一定的安全性。 3. 使用ssh-keygen重新生成密钥:如果你不确定目标主机的安全性,你可以尝试使用`ssh-keygen`命令生成新的公钥和私钥。然后,将新的公钥复制到目标主机的`~/.ssh/authorized_keys`文件中。这样可以确保安全连接和身份验证。 无论你选择哪种方法,记得在操作之前确保备份重要的配置文件和数据,以免意外损失。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值