打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ansible不配置ssh免密钥,使用密码登录

参考文档:
https://my.oschina.net/u/1433006/blog/1622893

1.安装sshpass
运行下列命令安装:

tar -zxvf sshpass-1.05.tar.gzcd sshpass-1.05                ./configure             make && make install

安装完成后输入sshpass出现如下提示即安装成功

#sshpass

Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters   -f filename   Take password to use from file   -d number     Use number as file descriptor for getting password   -p password   Provide password as argument (security unwise)   -e            Password is passed as env-var "SSHPASS"   With no parameters - password will be taken from stdin   -h            Show help (this screen)   -V            Print version informationAt most one of -f, -d, -p or -e should be used

/etc/ansible/hosts文件中添加用户密码,认证ssh连接

[test]127.0.0.1 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123456192.168.1.137 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123456

2.错误汇总:

[root@localhost ~]# ansible test -m ping

127.0.0.1 | FAILED! => {    "msg": "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."}192.168.1.103 | FAILED! => {    "msg": "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."}

3.原因和解决办法:
ssh第一次连接的时候一般会提示输入yes 进行确认为将key字符串加入到 ~/.ssh/known_hosts 文件中。而本机的~/.ssh/known_hosts文件中并有fingerprint key串
解决方法:在ansible.cfg文件中更改下面的参数:
#host_key_checking = False 将#号去掉即可

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
sshpass 用法举例
linux下SSH服务利用shell脚本实现密钥的批量分发与执行
shell 中使用 ssh 连接(sshpass)
利用ssh-keygen生成密钥对
zabbix自动发现和自动注册批量添加100台主机
利用pexpect模拟ssh连接
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服