【ansible】Failed to connect to the host via ssh Permission denied

故障现象

yeqiang@yeqiang-MS-7B23:/data/VirtualBox VMs$ ansible all -m ping
node-2 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: \nAuthorized users only. All activities may be monitored and reported.\nyeqiang@node-2: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
node-3 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: \nAuthorized users only. All activities may be monitored and reported.\nyeqiang@node-3: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}
node-1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: \nAuthorized users only. All activities may be monitored and reported.\nyeqiang@node-1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
"unreachable": true
}

故障原因:

当前用户是yeqiang,而配置ssh-copy-id 是root,参考以下指令

复制代码
ssh root@node-1
ssh root@node-2
ssh root@node-3

解决

ansible指令指定用户root即可

yeqiang@yeqiang-MS-7B23:/data/VirtualBox VMs$ ansible -u root all -m ping

WARNING: Platform linux on host node-1 is using the discovered Python interpreter at /usr/bin/python, but future

installation of another Python interpreter could change the meaning of that path. See

https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information.
node-1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
WARNING: Platform linux on host node-3 is using the discovered Python interpreter at /usr/bin/python3.9, but
future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information.
node-3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3.9"
},
"changed": false,
"ping": "pong"
}
WARNING: Platform linux on host node-2 is using the discovered Python interpreter at /usr/bin/python3.9, but
future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information.
node-2 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3.9"
},
"changed": false,
"ping": "pong"
}

相关推荐
枝枝在Coding10 小时前
我把 Codex 接进 SSH 后,才发现 Xterminal MCP 最难的是敢不敢让 Agent 动手
ssh·mcp
运维开发那些事12 小时前
GitOps最佳实践 (gitlab ci + ArgoCD)
ci/cd·devops
可乐ea12 小时前
Anthropic 的 CI/CD 值班智能体:Claude Tag 当一线响应者的架构拆解与踩坑复盘
ci/cd·架构·claude·devops·ai智能体·mcp
NJCloud1 天前
Ansible(三)——Zabbix 监控系统部署与敏感信息加密
linux·运维·chrome·信息可视化·ansible·zabbix
小张同学a.1 天前
练习:用 playbook 部署 zabbix 和 tidb
ansible·zabbix·tidb
Zadig1 天前
Zadig 全面支持 CRD,至此所有 K8s 资源类型均可一键发布!
后端·devops
整点bug1 天前
SSH 断开后,程序还在跑吗?
ssh
NJCloud1 天前
Ansible(四)——基于 Ansible Roles 的标准化运维任务编排实践
linux·运维·ansible
枝枝在Coding2 天前
服务器一多就容易连错:SSH 客户端里的分组和命名比快捷键更重要
ssh
小张同学a.2 天前
Ansible自动化运维实战3——变量分离、Roles 角色开发与 Git 托管分发实战
运维·服务器·自动化·ansible·playbook·role