Ansible: 无法通过 ssh 连接到主机:权限被拒绝(公钥,密码)

创建于 2016-12-20  ·  70评论  ·  资料来源: ansible/ansible

192.168.1.113 | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", 
    "unreachable": true
}

我有这个错误,我在 virtualbox 中使用 Debian Stretch 和来宾 manjaro。

affects_2.3

最有用的评论

好的,
当您在命令中指定all时,调试有点困难。

注释hosts文件中的所有行添加此行

[webserver]
35.165.79.66 ansible_user=ubuntu 

并尝试运行:

$: ansible webserver -m ping -vvv

并向我展示输出。
问候

所有70条评论

面临同样的问题。 下列的。

您能否使用-vvvv选项启动相同的命令以获得更多输出。 请 !

guru@tj-lp140:/etc/ansible$ ansible all -m ping -vvv
Using /etc/ansible/ansible.cfg as config file
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/ping.py
<35.165.79.66> ESTABLISH SSH CONNECTION FOR USER: None
<35.165.79.66> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/guru/.ansible/cp/ansible-ssh-%h-%p-%r 35.165.79.66 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1482309322.49-151682117578429 `" && echo ansible-tmp-1482309322.49-151682117578429="` echo /tmp/ansible-tmp-1482309322.49-151682117578429 `" ) && sleep 0'"'"'' 

谢谢。
从您的输出中,我看到您没有指定任何 ansible_user :

<35.165.79.66> ESTABLISH SSH CONNECTION FOR USER: None

Cat 你也显示了你的库存文件的内容吗?

# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

[webservers]
35.165.79.66

# If you have multiple hosts following a pattern you can specify
# them like this:

## www[001:006].example.com

# Ex 3: A collection of database servers in the 'dbservers' group

## [dbservers]
## 
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here's another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com

ssh [email protected]连接将建立。 但 ansible 命令无法完成。

好的,
当您在命令中指定all时,调试有点困难。

注释hosts文件中的所有行添加此行

[webserver]
35.165.79.66 ansible_user=ubuntu 

并尝试运行:

$: ansible webserver -m ping -vvv

并向我展示输出。
问候

guru@tj-lp140:/etc/ansible$ ansible webservers -m ping -vvv
Using /etc/ansible/ansible.cfg as config file
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/ping.py
<35.165.79.66> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<35.165.79.66> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o ControlPath=/home/guru/.ansible/cp/ansible-ssh-%h-%p-%r 35.165.79.66 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1482312980.96-238945640414494 `" && echo ansible-tmp-1482312980.96-238945640414494="` echo $HOME/.ansible/tmp/ansible-tmp-1482312980.96-238945640414494 `" ) && sleep 0'"'"''
<35.165.79.66> PUT /tmp/tmpxll2kJ TO /home/ubuntu/.ansible/tmp/ansible-tmp-1482312980.96-238945640414494/ping.py
<35.165.79.66> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o ControlPath=/home/guru/.ansible/cp/ansible-ssh-%h-%p-%r '[35.165.79.66]'
<35.165.79.66> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<35.165.79.66> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o ControlPath=/home/guru/.ansible/cp/ansible-ssh-%h-%p-%r 35.165.79.66 '/bin/sh -c '"'"'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1482312980.96-238945640414494/ /home/ubuntu/.ansible/tmp/ansible-tmp-1482312980.96-238945640414494/ping.py && sleep 0'"'"''
<35.165.79.66> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<35.165.79.66> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o ControlPath=/home/guru/.ansible/cp/ansible-ssh-%h-%p-%r -tt 35.165.79.66 '/bin/sh -c '"'"'/usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1482312980.96-238945640414494/ping.py; rm -rf "/home/ubuntu/.ansible/tmp/ansible-tmp-1482312980.96-238945640414494/" > /dev/null 2>&1 && sleep 0'"'"''
35.165.79.66 | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_name": "ping"
    }, 
    "module_stderr": "Shared connection to 35.165.79.66 closed.\r\n", 
    "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", 
    "msg": "MODULE FAILURE"
}
<192.168.1.113> ESTABLISH SSH CONNECTION FOR USER: fulgor
<192.168.1.113> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=fulgor -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.1.113 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1482330370.75-42265180130710 `" && echo ansible-tmp-1482330370.75-42265180130710="` echo $HOME/.ansible/tmp/ansible-tmp-1482330370.75-42265180130710 `" ) && sleep 0'"'"''
192.168.1.113 | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", 
    "unreachable": true
}

我更改了虚拟框中的映像磁盘,因此 ssh 密钥已重新生成,但从此时起我收到一条错误消息。

你可以帮帮我吗 ?

在主节点上生成 ssh 密钥:

root<strong i="6">@master</strong>:~# ssh-keygen -t rsa -C "[email protected]"

然后使用 ssh-copy-id 将您的公钥复制到服务器:

root<strong i="10">@master</strong>:~# ssh-copy-id [email protected]
root<strong i="11">@master</strong>:~# ssh-copy-id [email protected]

我在这个网站https://valdhaus.co/writings/ansible-post-install/上得到了这些信息并且它正在工作

@guruprasad85看起来你错过了远程机器上的“python”(35.165.79.66)。

"module_name": "ping"
},
"module_stderr": "Shared connection to 35.165.79.66 closed.\r\n",
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",
"msg": "MODULE FAILURE"
}

你好,
我找到了解决办法。
如果您使用的是 ami(ubuntu 16) 操作系统,则没有安装 python,因此您需要安装它。 使用以下命令安装 python -

sudo apt-get install python-minimal -y

或者

您需要使用 ami(ubuntu 14) 操作系统。 它有 python 2.7。

注意:确认您系统中的操作系统版本。

很高兴您找到了解决方案。

我正在尝试从 Ansible 控制机器(安装在 UBUNTU 14.04 VM 中)ping 到一个 Cent OS 实例。
两者都是谷歌云实例(安装了python)。
我不确定它们之间的连接状态。 从 ansible all -m ping 的以下结果中,我可以看到我的 SSH 有问题。

35.185.191.25 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\n",
    "unreachable": true
# ansible all -m ping -vvv
Using /etc/ansible/ansible.cfg as config file
META: ran handlers
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/ping.py
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: None
<127.0.0.1> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/21f0e6a9ae 127.0.0.1 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/ping.py
<35.185.191.25> ESTABLISH SSH CONNECTION FOR USER: gane
<35.185.191.25> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=gane -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4596e88996 35.185.191.25 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<127.0.0.1> (255, '', 'Permission denied (publickey).\r\n')
127.0.0.1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey).\r\n",
    "unreachable": true
}
<35.185.191.25> (255, '', 'Permission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\n')
35.185.191.25 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\n",
    "unreachable": true
}

你能建议我实现我的虚拟机之间的连接吗?

我有同样的问题@ganfotry 。 这个问题的原因是什么? 请指导我正确的方式。

我通过在两个虚拟机中生成密钥然后复制密钥来修复它
在authorized_keys 中反之亦然。
然后我得到了以下回复:)

ansible -m ping all
127.0.0.1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
35.186.***.*** | SUCCESS => {
    "changed": false,
    "ping": "pong"

我遇到了同样的问题:

$ ansible local -m ping
127.0.0.1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n",
"unreachable": true
}

通过使用以下命令安装 sshpass 解决了该问题:

sudo apt-get install sshpass

安装 sshpass 后,我执行了这个命令:
` json ansible local -m ping --ask-pass SSH password: 127.0.0.1 | SUCCESS => { "changed": false, "ping": "pong" }
希望这可以帮助!!!

这对我有用,所以也可以帮助你。
尝试将私钥注册到您的钥匙串

ssh-agent bash
ssh-add <path to private key>

如果可行,请尝试将密钥添加到您的 ~/.ssh/config 文件中

你好,
在 ansible 塔式 GUI 模式下运行命令时出现以下错误。

192.168.122.136 | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Warning: Permanently added '192.168.122.136' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey,password).\r\n", 
    "unreachable": true 
}

但是我能够在服务器上以 CLI 模式获得结果。

[root<strong i="10">@node2</strong> ~]# ansible -m ping testservers
openstack | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

下面是描述的输出

[root<strong i="14">@node2</strong> ~]# ansible testservers -m ping -vvv
Using /etc/ansible/ansible.cfg as config file
META: ran handlers
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/ping.py
<192.168.122.136> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.122.136> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/859aa03053 192.168.122.136 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<192.168.122.136> (0, '/root\n', '')
<192.168.122.136> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.122.136> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/859aa03053 192.168.122.136 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696 `" && echo ansible-tmp-1497787246.45-142355876761696="` echo /root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696 `" ) && sleep 0'"'"''
<192.168.122.136> (0, 'ansible-tmp-1497787246.45-142355876761696=/root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696\n', '')
<192.168.122.136> PUT /tmp/tmpkAYqIN TO /root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696/ping.py
<192.168.122.136> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/859aa03053 '[192.168.122.136]'
<192.168.122.136> (0, 'sftp> put /tmp/tmpkAYqIN /root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696/ping.py\n', '')
<192.168.122.136> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.122.136> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/859aa03053 192.168.122.136 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696/ /root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696/ping.py && sleep 0'"'"''
<192.168.122.136> (0, '', '')
<192.168.122.136> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.122.136> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/859aa03053 -tt 192.168.122.136 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696/ping.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1497787246.45-142355876761696/" > /dev/null 2>&1 && sleep 0'"'"''
<192.168.122.136> (0, '\r\n{"invocation": {"module_args": {"data": null}}, "changed": false, "ping": "pong"}\r\n', 'Shared connection to 192.168.122.136 closed.\r\n')
openstack | SUCCESS => {
    "changed": false, 
    "invocation": {
        "module_args": {
            "data": null
        }
    }, 
    "ping": "pong"
}
META: ran handlers
META: ran handlers

谢谢

手动尝试在终端上访问服务器,如果您能够 ssh 远程服务器,则从本地用户的主目录中删除 .ansible 目录。 这对我有用。 (y)

我也是!
我可以通过终端 SSH 服务器而不通过 -i 指令:

ssh [email protected]

作品

执行命令:

ansible all -m ping

我收到错误:

    "msg": "Failed to connect to the host via ssh: Permission denied (publickey).\r\n",  
    "unreachable": true

@lkjangir删除 .ansible 目录也不起作用。 =(

试试这个,用你设置的任何用户名替换 ec2-user 。

ansible all -u ec2-user -m ping -vvv

@aelkz :在 /etc/ansible/hosts 文件中,您可以输入: [email protected]而不是server.com ,然后尝试ansible all -m ping
否则,如果你没有在 /etc/ansible/hosts 中指定 user1,你应该在 ansible 命令中指定用户: ansible all -m ping -u user1
我遇到了同样的错误,该解决方案解决了我的问题。

如果我没有错,这是由于 ssh 密钥问题。 Rene 新密钥的速率或将您的密钥转换为 openssh 格式以避免错误。

使用 --ask-pass 和 -u 参数对我有用。

@Hai-minhD 您的解决方案对我有用,谢谢。 我在主机上进行测试,我的 root 用户与我在控制机器中使用的用户相同。 在我收到上面报告的故障的这个特定主机中,我有一个不同的用户。 解决了在 Ansible 主机文件中添加具有此用户名的主机的问题: username@host。

尝试-

ansible webserver -m ping --ask-pass -i path_to_local_hosts_file

在 slave 上安装了 python,它对我有用。

我有同样的问题。
我找到解决方案:我添加/etc/ansible/hosts:
ansible_ssh_user=ansible_ssh_pass=.

希望这可以帮助。

得到一个错误。 这里 shivslave 是 Virtualbox 上的另一个虚拟机,IP 为 192.168.0.5,我能够成功地将它与[email protected]连接,但 Ansible 命令不起作用。 主机文件包含

[例子]192.168.0.5

shivmaster@shivmaster-VirtualBox :~$ ansible 示例 -m ping -u shivslave -vvv
安全的 2.4.1.0
配置文件 = /etc/ansible/ansible.cfg
配置的模块搜索路径 = [u'/home/shivmaster/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python 模块位置 = /usr/lib/python2.7/dist-packages/ansible
可执行位置 = /usr/bin/ansible
python 版本 = 2.7.6(默认,2016 年 10 月 26 日,20:30:19)[GCC 4.8.4]
使用 /etc/ansible/ansible.cfg 作为配置文件
使用 ini 插件解析 /etc/ansible/hosts 库存源
META:运行处理程序
使用模块文件 /usr/lib/python2.7/dist-packages/ansible/modules/system/ping.py
<192.168.0.5> 为用户建立 SSH 连接:shivslave
<192.168.0.5> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o用户=shivslave -o ConnectTimeout=10 -o ControlPath=/home/shivmaster/.ansible/cp/e51c1eb9be 192.168.0.5 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<192.168.0.5> (255, '', '权限被拒绝(公钥、密码)。\r\n')
192.168.0.5 | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机:权限被拒绝(公钥,密码)。\r\n",
“无法访问”:true
}
shivmaster@shivmaster-VirtualBox :~$

@lktslionel
我遇到了同样的问题,我已经尝试了上面提到的所有选项,你能在这里帮忙吗

安全的 2.4.2.0
配置文件 = /etc/ansible/ansible.cfg
配置的模块搜索路径 = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python 模块位置 = /usr/lib/python2.7/dist-packages/ansible
可执行位置 = /usr/bin/ansible
python 版本 = 2.7.12(默认,2017 年 11 月 20 日,18:23:56)[GCC 5.4.0 20160609]
使用 /etc/ansible/ansible.cfg 作为配置文件
可以通过在 ansible.cfg 中设置 deprecation_warnings=False 来禁用。
设置库存插件
使用 ini 插件解析 /etc/ansible/hosts 库存源
从 /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc 加载最小类型 stdout,v2.0 的回调插件
META:运行处理程序
使用模块文件 /usr/lib/python2.7/dist-packages/ansible/modules/system/ping.py
<10.0.3.36> 为用户建立 SSH 连接:root
<10.0.3.36> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi- keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/c8171a76d6 10.0.3.36 '/bin/sh -c '"'"'echo ~ && 睡眠 0'"'"''
<10.0.3.36> (255, '', 'OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016\r\ndebug1: 读取配置数据 /etc/ssh/ssh_config\r\ndebug1: /etc/ ssh/ssh_config 第 19 行:为\r\ndebug1应用选项sh/id_dsa-cert 类型 -1\r\ndebug1: 身份文件 /root/.ssh/id_ecdsa 类型 3\r\ndebug1: key_load_public: 没有这样的文件或目录\r\ndebug1: 身份文件 /root/.ssh/id_ecdsa -cert type -1\r\ndebug1: key_load_public: 没有那个文件或目录\r\ndebug1: 身份文件 /root/.ssh/id_ed25519 type -1\r\ndebug1: key_load_public: 没有那个文件或目录\r\ndebug1 : 身份文件 /root/.ssh/id_ed25519-cert type -1\r\ndebug1: 启用协议 2.0 的兼容模式\r\ndebug1: 本地版本字符串 SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2\r\ndebug1 : 远程协议版本2.0,远程软件版本OpenSSH_7.2p2 Ubuntu-4ubuntu2.2\r\ndebug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH compat 0x04000000\r\ndebug2: fd 3 setting O_NONBLOCK1\r\n以 \'root\' 身份验证到 10.0.3.36:22\r\ndebug3:hostkeys_foreach:读取文件“/root/.ssh/known_hosts”\r\ndebug3:record_hostkey:在文件 /root/.ssh/ 中找到密钥类型 ECDSA known_hosts:1\r\ndebug3: load_hostkeys: 从 10.0 加载 1 个密钥 .3.36\r\ndebug3:order_hostkeyalgs:更喜欢hostkeyalgs:[email protected],[email protected],ecdsa-sha2-nistp5021@cert openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521\r\ndebug3: 发送数据包: 类型 20\r\ndebug1: SSH2_MSG_KEXINIT 发送\r\ndebug3: 接收数据包: 类型 20\r \ndebug1: SSH2_MSG_KEXINIT 收到\r\ndebug2: 本地客户端 KEXINIT 提议\r\ndebug2: KEX 算法: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdisth-sha21 hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,ext-info-c\r\ndebug2:主机密钥算法:ecdsa-sha2-nistp256-cert-v01@ openssh.com,[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 [email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa\r\ndebug2:密码ctos : chacha20-po [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc r\ndebug2: 密码 stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes,aes192-ctr ,aes256-cbc,3des-cbc\r\ndebug2: MACs ctos: [email protected],[email protected],[email protected],hmac- [email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac- sha1\r\ndebug2: MACs stoc: [email protected],[email protected],[email protected],hmac-sha2-512-etm@openssh .com,[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2:压缩ctos: [email protected],zlib,none\r\ndebug2: 压缩 stoc: [email protected],zlib,none\r\ndebug2: 语言 ctos: \r\ndebug2: 语言 stoc: \r\ndebug2: first_kex_follows 0 \r\ndebug2: r 保留 0 \r\ndebug2:对等服务器 KEXINIT 提案\r\ndebug2:KEX 算法:[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffgroupie-hellman -exchange-sha256,diffie-hellman-group14-sha1\r\ndebug2:主机密钥算法:ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519\r\ndebug2 : 密码 ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]\r\ndebug2: cipherspolycha20stoc @openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]\r\ndebug2: MACs ctos: [email protected], [email protected],[email protected],[email protected],[email protected],umac-64@openssh。 com,[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2: MACs stoc: [email protected],umac-128-etm@openssh .com,[email protected],[email protected],[email protected],umac-64@open ssh.com,[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2: 压缩 ctos: 无,[email protected]\r\ndebug2: 压缩 stoc: none,[email protected]\r\ndebug2: 语言 ctos: \r\ndebug2: 语言 stoc: \r\ndebug2: first_kex_follows 0 \r\ndebug2: 保留 0 \r\ndebug1: kex: 算法: curve25519-sha256@ libssh.org\r\ndebug1: kex: 主机密钥算法: ecdsa-sha2-nistp256\r\ndebug1: kex: server->client cipher: [email protected] MAC:压缩:[email protected]\r\ndebug1:kex:客户端->服务器密码:[email protected] MAC:压缩:[email protected]\r\ndebug3:发送数据包:类型 30\r\ndebug1:期待 SSH2_MSG_KEX_ECDH_REPLY\r\ndebug3:接收数据包:类型 31\r\ndebug1:服务器主机密钥:ecdsa-sha2-nistp256 SHA256 JDiSsUdyRJfRGvtqAURzMtKu/Ghp0adBt/l9VbvgDfg\r\ndebug3:hostkeys_foreach:读取文件“/root/.ssh/known_hosts”\r\ndebug3:record_hostkey:在文件/root/.ssh1/known_hosts中找到密钥类型ECDSA load_hostkeys:从 10.0.3.36 加载了 1 个密钥\r\ndebug1:主机 \'10.0.3.36\' 已知并且与 ECDSA 主机密钥匹配。\r\ndebug1:在 /root/.ssh/known_hosts:1 中找到密钥\r \ndebug3:发送数据包:类型 21\r\ndebug2:set_newkeys:模式 1\r\ndebug1:在 134217728 块后重新加密\r\ndebug1:发送 SSH2_MSG_NEWKEYS\r\ndebug1:期待 SSH2_MSG_NEWKEYS:接收类型数据包\r\ndebug1: \r\ndebug2:set_newkeys:模式 0\r\ndebug1:在 134217728 个块后重新加密\r\ndebug1:收到 SSH2_MSG_NEWKEYS\r\ndebug2:密钥:/root/.ssh/id_ecdsa (0x55cbdc34d840),代理: /root/.ssh/id_rsa (0x55cbdc33fc30)\r\ndebug 2: key: /root/.ssh/id_dsa ((nil))\r\ndebug2: key: /root/.ssh/id_ed25519 ((nil))\r\ndebug3: send packet: type 5\r\ndebug3:接收数据包:类型 7\r\ndebug1: SSH2_MSG_EXT_INFO 收到\r\ndebug1: kex_input_ext_info: server-sig-algs=\r\ndebug3:接收数据包:类型 6\r\ndebug2:service_accept:ssh-userauth\r\ndebug1:接收到 SSH2_MSG_SERVICE_ACCEPT\r\ndebug3:发送数据包:类型 50\r\ndebug3:接收数据包:类型 51\r\ ndebug1: 可以继续的身份验证: publickey,password\r\ndebug3: 重新开始,传递不同的列表 publickey,password\r\ndebug3: 首选 gssapi-with-mic,gssapi-keyex,hostbased,publickey\r\ndebug3: authmethod_lookup publickey\r\ndebug3: 剩余首选: ,gssapi-keyex,hostbased,publickey\r\ndebug3: authmethod_is_enabled publickey\r\ndebug1: 下一个身份验证方法: publickey\r\ndebug1: 提供 ECDSA 公钥: /root/.ssh/ id_ecdsa\r\ndebug3:send_pubkey_test\r\ndebug3:发送数据包:类型50\r\ndebug2:我们发送了一个公钥数据包,等待回复\r\ndebug3:接收数据包:类型51\r\ndebug1:可以继续的身份验证:公钥,密码\r\ndebug1:提供RSA公钥:/root/.ssh/id_rsa\r\ndebug3:send_pubkey_test\r\ndebug3:发送数据包:类型50\r\ndebug2:我们发送了一个公钥数据包,等待回复\r\ndebug3:接收数据包:类型 51\r\ndebug1:可以继续的身份验证:公钥,密码\r\ndebug1:尝试私钥:/root/.ssh/id_dsa\r\ndebug3:否这样的身份:/root/.ssh/id_dsa:没有这样的文件或目录\r\ndebug1:正在尝试私钥:/root/.ssh/id_ed25519\r\ndebug3:没有这样的身份:/root/.ssh/id_ed25519:没有此类文件或目录\r\ndebug2: 我们没有发送数据包,禁用方法\r\ndebug1: 没有更多的身份验证方法可以尝试。\r\n权限被拒绝(公钥,密码)。\r\n')
10.0.3.36 | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机:OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016\r\ndebug1: 读取配置数据 /etc/ssh/ssh_config\r\ndebug1: / etc/ssh/ssh_config 第 19 行:为\r\ndebug1应用选项bug1:身份文件/root/.ssh/id_dsa-cert 类型-1\r\ndebug1:身份文件/root/.ssh/id_ecdsa 类型3\r\ndebug1:key_load_public:没有那个文件或目录\r\ndebug1:身份文件 /root/.ssh/id_ecdsa-cert type -1\r\ndebug1: key_load_public: 没有那个文件或目录\r\ndebug1: 身份文件 /root/.ssh/id_ed25519 type -1\r\ndebug1: key_load_public: 没有此类文件或目录\r\ndebug1:身份文件/root/.ssh/id_ed25519-cert type -1\r\ndebug1:启用协议2.0的兼容模式\r\ndebug1:本地版本字符串SSH-2.0-OpenSSH_7.2p2 Ubuntu -4ubuntu2.2\r\ndebug1:远程协议版本2.0,远程软件版本OpenSSH_7.2p2 Ubuntu-4ubuntu2.2\r\ndebug1:匹配:OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH compat 0x04000000\r\ndebug2 3 设置 O_NONBLOCK\r\ndebug1: Authenticating to 10.0.3.36:22 as 'root'\r\ndebug3: hostkeys_foreach: reading file \"/root/.ssh/known_hosts\"\r\ndebug3: record_hostkey: found key type ECDSA在文件 /root/.ssh/known_hosts:1\r\ndebug3: load_hostk eys:从 10.0.3.36 加载了 1 个密钥\r\ndebug3:order_hostkeyalgs:更喜欢 hostkeyalgs:[email protected],[email protected],ecdsa [email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521\r\ndebug3:发送数据包:类型20\r\ndebug1:SSH2_MSG_KEXINIT3:发送\r接收数据包:类型20\r\ndebug1:SSH2_MSG_KEXINIT收到\r\ndebug2:本地客户端KEXINIT提案\r\ndebug2:KEX算法:[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp38 -sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,ext-info-c\r\ndebug2:主机密钥算法:ecdsa-sha2 [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp388 ,ecdsa-sha2-nistp521,[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa \r\n调试 2:密码ctos:[email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes128-cbc,aes25c61 -cbc,3des-cbc\r\ndebug2: 密码 stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],aes256-gcm,@openssh aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc\r\ndebug2: MACs ctos: [email protected],[email protected],hmac-sha2-256-etm @openssh.com,[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac -sha2-512,hmac-sha1\r\ndebug2: MACs stoc: [email protected],[email protected],[email protected],hmac- [email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac- sha1\r\ndebug2: 压缩 ctos: [email protected],zlib,none\r\ndebug2: 压缩 stoc: [email protected],zlib,none\r\ndebug2: 语言 ctos: \r\ndebug2: 语言 stoc : \r\ndebug2: 首先 _kex_follows 0 \r\ndebug2:保留 0 \r\ndebug2:对等服务器 KEXINIT 提案\r\ndebug2:KEX 算法:[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp382,ecdh nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1\r\ndebug2: 主机密钥算法: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256, ssh-ed25519\r\ndebug2: 密码 ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],aes256-gcm\rnsh.com : 密码 stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]\r\ndebug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected] ,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2: MACs stoc: [email protected], [email protected],[email protected],[email protected],hmac-sha1- [email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2: 压缩 ctos: none,zlib@openssh .com\r\ndebug2: 压缩 stoc: none,[email protected]\r\ndebug2: 语言 ctos: \r\ndebug2: 语言 stoc: \r\ndebug2: first_kex_follows 0 \r\ndebug2: reserved 0 \r\ ndebug1:kex:算法:[email protected]\r\ndebug1:kex:主机密钥算法:ecdsa-sha2-nistp256\r\ndebug1:kex:服务器->客户端密码:[email protected] MAC :压缩:[email protected]\r\ndebug1:kex:客户端->服务器密码:[email protected] MAC:压缩:[email protected]\r\ndebug3:发送数据包:类型 30\r\ndebug1:期待 SSH2_MSG_KEX_ECDH_REPLY\r\ndebug3:接收数据包:类型 31\r\ndebug1:服务器主机密钥:ecdsa-sha2-nistp256 SHA256 JDiSsUdyRJfRGvtqAURzMtKu/Ghp0adBt/l9VbvgDfg\r\ndebug3:hostkeys_foreach:读取文件\"/root/.ssh/known_hosts\"\r\ndebug3:record_hostkey:在文件/root/.ssh1/knownr中找到密钥类型ECDSA ndebug3: load_hostkeys: 从 10.0.3.36 加载了 1 个密钥\r\ndebug1: 主机“10.0.3.36”是已知的并且匹配 ECDSA 主机密钥。\r\ndebug1: 在 /root/.ssh/known_hosts:1 中找到密钥\r \ndebug3:发送数据包:类型 21\r\ndebug2:set_newkeys:模式 1\r\ndebug1:在 134217728 块后重新加密\r\ndebug1:发送 SSH2_MSG_NEWKEYS\r\ndebug1:期待 SSH2_MSG_NEWKEYS:接收类型数据包\r\ndebug1: \r\ndebug2:set_newkeys:模式 0\r\ndebug1:在 134217728 个块后重新加密\r\ndebug1:收到 SSH2_MSG_NEWKEYS\r\ndebug2:密钥:/root/.ssh/id_ecdsa (0x55cbdc34d840),代理: /root/.ssh/id_rsa (0x55cbdc33fc30)\r\ndebug 2: key: /root/.ssh/id_dsa ((nil))\r\ndebug2: key: /root/.ssh/id_ed25519 ((nil))\r\ndebug3: send packet: type 5\r\ndebug3:接收数据包:类型 7\r\ndebug1: SSH2_MSG_EXT_INFO 收到\r\ndebug1: kex_input_ext_info: server-sig-algs=\r\ndebug3:接收数据包:类型 6\r\ndebug2:service_accept:ssh-userauth\r\ndebug1:接收到 SSH2_MSG_SERVICE_ACCEPT\r\ndebug3:发送数据包:类型 50\r\ndebug3:接收数据包:类型 51\r\ ndebug1: 可以继续的身份验证: publickey,password\r\ndebug3: 重新开始,传递不同的列表 publickey,password\r\ndebug3: 首选 gssapi-with-mic,gssapi-keyex,hostbased,publickey\r\ndebug3: authmethod_lookup publickey\r\ndebug3: 剩余首选: ,gssapi-keyex,hostbased,publickey\r\ndebug3: authmethod_is_enabled publickey\r\ndebug1: 下一个身份验证方法: publickey\r\ndebug1: 提供 ECDSA 公钥: /root/.ssh/ id_ecdsa\r\ndebug3:send_pubkey_test\r\ndebug3:发送数据包:类型50\r\ndebug2:我们发送了一个公钥数据包,等待回复\r\ndebug3:接收数据包:类型51\r\ndebug1:可以继续的身份验证:公钥,密码\r\ndebug1:提供RSA公钥:/root/.ssh/id_rsa\r\ndebug3:send_pubkey_test\r\ndebug3:发送数据包:类型50\r\ndebug2:我们发送了一个公钥数据包,等待回复\r\ndebug3:接收数据包:类型 51\r\ndebug1:可以继续的身份验证:公钥,密码\r\ndebug1:尝试私钥:/root/.ssh/id_dsa\r\ndebug3:否这样的身份:/root/.ssh/id_dsa:没有这样的文件或目录\r\ndebug1:正在尝试私钥:/root/.ssh/id_ed25519\r\ndebug3:没有这样的身份:/root/.ssh/id_ed25519:没有此类文件或目录\r\ndebug2: 我们没有发送数据包,禁用方法\r\ndebug1: 没有更多的身份验证方法可以尝试。\r\n权限被拒绝(公钥,密码)。\r\n",
“无法访问”:true
}
root@ip-172-31-31-140:~/.ssh#

我遇到了同样的问题,ansible 尝试使用您当前的用户名进行连接,因此我的解决方法是覆盖用户名,例如:
ansible all -m ping -u ec2-user

我在运行“ansible all -m ping”时遇到了两个错误,并偶然发现了这个线程来进行 t-shoot。 我要感谢大家的投入,因为它帮助我解决了这个问题。

:错误-1:
修复此消息的步骤:“msg”:“无法通过 ssh 连接到主机:权限被拒绝(公钥、密码)。\r\n”
1)我修改了 /etc/ansible/hosts 中的修复配置文件以包含正确的用户名“ubuntu”
2)我传递了'--private-key=/Users/my-user/.ssh/my-key.pem'的参数,所以命令看起来像这样:
ansible all -m ping --private-key=/Users/my-user/.ssh/my-key.pem
本指南告诉我如何将密钥作为参数传递:
https://ansible-tips-and-tricks.readthedocs.io/en/latest/ansible/commands/

:错误 2:
"module_stdout": "/bin/sh: 1: /usr/bin/python: 未找到\r\n",
为了修复我跑了'sudo apt-get update; sudo apt-get install python' 在远程主机上。 我正在使用 ec2 实例。 旁注,将安装命令作为启动脚本的一部分运行将有助于解决第二个问题。

干杯!

看起来我们的 Ubuntu 16.04 服务器上缺少 python。 我将它安装在所有远程主机上并解决了这个问题:
须藤 apt-get install python-minimal -y

SSH 将与终端连接,但不能与 vsts 和 ansible 连接,任何人都可以帮助我

尝试将 SSH 连接设置为* @10.130.2.142:22
2018-04-04T21:56:46.6533908Z
2018-04-04T21:56:46.6549162Z PLAY [全部] * * * * * * * * * * * * * * * * * * * * *
2018-04-04T21:56:46.6555625Z
2018-04-04T21:56:46.6603308Z
2018-04-04T21:56:46.6616154Z 任务 [创建目录] * * * * * * * * * * * * * * * *
2018-04-04T21:56:46.6622522Z
2018-04-04T21:56:46.8874071Z 失败:[10.130.2.206] (item=/home/ * /myagent/) => {"item": "/home/ * /myagent/", "msg": "无法通过 ssh 连接到主机:权限被拒绝(公钥)。\r\n", "unreachable": true}
2018-04-04T21:56:46.8880968Z
2018-04-04T21:56:47.0341093Z 失败:[10.130.2.206] (item=/home/ * /mywork/) => {"item": "/home/ * /mywork/", "msg": "无法通过 ssh 连接到主机:权限被拒绝(公钥)。\r\n", "unreachable": true}
2018-04-04T21:56:47.0349137Z
2018-04-04T21:56:47.0363780Z 致命:[10.130.2.206]:无法访问! => {"changed": false, "msg": "所有项目完成", "results": [{"_ansible_ignore_errors": null, "_ansible_item_result": true, "item": "/home/ * /myagent/" , "msg": "无法通过 ssh 连接到主机:权限被拒绝(公钥)。\r\n", "unreachable": true}, {"_ansible_ignore_errors": null, "_ansible_item_result": true, "item" : "/home/ * /mywork/", "msg": "无法通过 ssh 连接到主机:权限被拒绝 (publickey)。\r\n", "unreachable": true}]}
2018-04-04T21:56:47.0371817Z
2018-04-04T21:56:47.0387681Z 重试,使用:--limit @/tmp/Infrax/Agent_config.retry
2018-04-04T21:56:47.0397434Z
2018-04-04T21:56:47.0403265Z
2018-04-04T21:56:47.0415230Z PLAY重点回顾* * * * * * * * * * * * * * * * * * * * *
2018-04-04T21:56:47.0421749Z
2018-04-04T21:56:47.0434107Z 10.130.2.206:ok=0 改变=0 无法访问=1 失败=0
2018-04-04T21:56:47.0440861Z
2018-04-04T21:56:47.0446720Z
2018-04-04T21:56:47.0452765Z
2018-04-04T21:56:47.0850279Z ##[error] 命令 ansible-playbook -i "10.130.2.206," /tmp/Infrax/Agent_config.yaml -b --become-user *以代码 4 退出。
2018-04-04T21:56:47.0948275Z ##[section]整理:运行剧本

当我点击这个时,我在 OSX 上使用 Ansible 连接到带有 pem 证书的 aws 框。 我没有 ~/.ssh/config 文件。 一旦我创建了一个并添加了以下内容:

主持人 *
身份文件 ~/.ssh/id_rsa
AddKeysToAgent 是

然后我神奇地能够执行剧本。

尝试将文件从控制机器复制到节点时出现以下错误。

命令:sudo ansible dbservers -m copy -a "src=/etc/ansible/Taha dest=/etc/Taha"
错误:
52.186.71.70 | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机:权限被拒绝 (publickey,gssapi-keyex,gssapi-with-mic,password,keyboard-interactive)。\r\n",
“无法访问”:true
}

我尝试了上面列出的所有步骤,仍然没有成功......

尝试使用用户名传递清单文件和 ssh 密钥。 我没有在节点的清单中定义任何用户,所以我通过命令传递,它总是对我有用。 所以命令将是这样的 -

sudo ansible dbservers -m -i inventory/inventory-file --user=ubuntu --private-key="private-key.pem" copy -a "src=/etc/ansible/Taha dest=/etc/Taha"

感谢 Lokesh 的帮助...

由于我是 ansible 的新手,我只想知道我可以在哪里将 pem 文件保存在控制服务器上? 我需要在库存文件中进行更改吗?

嗨,伙计们,
我有同样的问题。
我的 devops 用户可以通过 ssh 连接到所有服务器,但是当我尝试运行(使用 mysuer)ansible 命令时,我总是遇到错误......无法访问! ...
我通过使用“mysuer”ssh serverDestiny(库存文件中的服务器)注释解决了这个问题,如果您使用 fqdn,则必须将 ssh 连接到 FQDN。
例子:
猫库存
服务器 1

[ myuser@workstation ansible-deploy-cr] ssh-keygen
[ myuser@workstation ansible-deploy-cr] ssh-copy-id -i devops@server1
测试..
[ myuser@workstation ansible-deploy-cr] ssh ' devops@server1

希望这会帮助你。
如果有,给个赞👍
谢谢,
美布里托

10.20.2.42
ansibleclient.com

[root @ansibleserver ~]# ansible all -m ping
10.20.2.42 | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机:权限被拒绝 (publickey,gssapi-keyex,gssapi-with-mic,password)。\r\n",
“无法访问”:true
}
ansibleclient.com | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机:权限被拒绝(公钥,密码)。\r\n",
“无法访问”:true
}
[ root@ansibleserver ~]#

请帮我解决这个问题..我想我们需要创建 ssh 密钥的如何创建逐步过程请我不是专家

请帮忙

这是通过将生成 ssh 密钥添加到服务器并将其复制到客户端来解决的

命令:

$ ssh-keygen -t rsa

按回车

$光盘根/
$ la -la

将 id_rsa.pub 复制到目标虚拟机
$ssh-copy-id 目标虚拟机

ssh-copy-id -i用户@本地主机
ssh-copy-id -i user@servers_in_inventory

似乎工作

此 URL 是此错误的排名第一的 Google 命中,因此,尽管此“问题”已关闭,但在可预见的未来,人们仍会继续点击此 URL。 这是我为python3ansible 2.5 (都是 PIP 版本,在 virutualenv 中)和 OSX High Sierra 修复它的方法。
针对我的情况报告我的“修复”。 跑步:
$ python3 $(ansible) localhost -m ping -vvvv

会导致这个错误。 -vvvv 表明这是一个密钥/身份验证失败。 伟大的。 您可以通过简单地执行[email protected]将 Ansible 与此隔离,对我来说它失败了(我认为使用 SSH 密钥登录失败是失败的)。

简单修复: at ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

我遇到了同样的问题,我自己得到了解决方案,我会告诉你发生在我身上的事情。
我遇到了同样的错误,我在同一个 proyect 文件夹中解决了它,我有一个主机文件,由于某种原因,出现了错误,所以只使用 rm -r hosts,我就解决了。
如果你有和我一样的问题,我会告诉你。

圣诞快乐 X),xoxo。

在我编辑库存文件之前,我遇到了同样的问题
[testserver]
<target_ip> ansible_user=<target_domain_name> ansible_ssh_pass=<target_pass>
然后进行测试:
ansible testserver -m ping

ubuntu@ip-172-31-1-85 :/etc/ansible$ sudo ansible-playbook tomserver.yml

PLAY [Web服务器] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **

TASK [收集事实] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
致命:[54.153.119.230]:无法访问! => {"changed": false, "msg": "无法通过 ssh 连接到主机:没有这样的身份:/root/UbuntuAnsible.pem: 没有这样的文件或目录\r\n权限被拒绝(公钥)。\r \n", "无法访问": true}
要重试,请使用:--limit @/etc/ansible/tomserver.retry

请帮忙

你想简单地连接吗? 你的主机文件是什么样的?

2018 年 9 月 12 日,星期三,FALCON-SJSU通知@github.com
写道:

致命:[54.153.119.230]:无法访问! => {“更改”:false,“msg”:“失败
通过 ssh 连接到主机:没有这样的身份:/root/UbuntuAnsible.pem:
没有这样的文件或目录\r\n权限被拒绝(公钥)。\r\n",
“无法访问”:真}
要重试,请使用:--limit @/etc/ansible/tomserver.retry

请帮忙


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/ansible/ansible/issues/19584#issuecomment-420827308
或静音线程
https://github.com/notifications/unsubscribe-auth/An-8H0G3NUSkpFXpcm2hkAXXGco3eMmyks5uaZO0gaJpZM4LSWpz
.

我找到了解决办法。
我的操作系统是 Mac OS ,我更改了 'remote_user = root ' 行中的 'ansible.cfg',问题解决了。

对! 我不得不做同样的事情! 很高兴你解决了它!

2018 年 9 月 18 日,星期二,上午 4:09 ZhangZhongyuan通知@github.com
写道:

我找到了解决办法。
我的操作系统是 Mac OS ,我更改了“ansible.cfg”
行 'remote_user = root ' ,问题解决了。


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/ansible/ansible/issues/19584#issuecomment-422297005
或静音线程
https://github.com/notifications/unsubscribe-auth/An-8H0zGJ4zE4mKmaMtXDAtInZNDlrW4ks5ucKpCgaJpZM4LSWpz
.

我使用以下标志运行剧本:

ansible-playbook playbook.yml --ask-pass - 这有帮助。

在主机中你也可以做 ansibleuser="user" ansiblepass="pass" right
在目标 IP 旁边。 这使我可以在没有任何内容的情况下运行剧本
额外的密码提示。

在星期二,2018年10月2日上午11:15 jluntnscc [email protected]写道:

我使用以下标志运行剧本:

ansible-playbook playbook.yml --ask-pass - 这有帮助。


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/ansible/ansible/issues/19584#issuecomment-426312089
或静音线程
https://github.com/notifications/unsubscribe-auth/An-8HzRVj8-BqcUiQywgQYKIVbcr4yzdks5ug4MEgaJpZM4LSWpz
.

试试这个

所有服务器 - 当服务器和客户端的用户名相同时工作(无密码)

ansible all -m ping

所有服务器 - “raj” 是托管节点的用户(无密码)

ansible all -u raj -m ping

或者

只有演示服务器组 - “raj”是管理节点的用户(无密码)

ansible 演示服务器 -u raj -m ping

或者

如果您使用密码验证

ansible -m ping all -u raj --ask-pass

或者您可以点击此链接以获取更多信息
https://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/install-ansible-automation-tool-for-it-management-on-centos-7-ubuntu-14-04-fedora- 22-part-1.html

对我有用的是更新我的主机文件以获取 ssh 密钥的路径:

[webserver]
IP_ADDRESS ansible_user=ubuntu ansible_connection=ssh ansible_private_key_file=~/.ssh/key.pem

不错的解决方案。 这将照顾多个目标!

在周一,2018年10月29日在下午4时02 fhackenb [email protected]写道:

对我有用的是更新我的主机文件以获取 ssh 的路径
钥匙:

[网络服务器]
IP_ADDRESS ansible_user=ubuntu ansible_connection=ssh ansible_private_key_file=~/.ssh/key.pem


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/ansible/ansible/issues/19584#issuecomment-434057611
或静音线程
https://github.com/notifications/unsubscribe-auth/An-8HzLY4PQVaWdPDOH0bHGnh9xpzmDWks5up17AgaJpZM4LSWpz
.

@riteshpuj2013解决方案之后工作正常。

ansible-playbook test.yml --ask-pass

我得到这个问题,不知道如何进展

[email protected] | 无法访问! => {
“改变”:假,
"msg": "身份验证或权限失败。在某些情况下,您可能已经能够进行身份验证但对目标目录没有权限。考虑将 ansible.cfg 中的远程 tmp 路径更改为根目录为 \"/tmp 的路径\"。失败的命令是:( umask 77 && mkdir -p \" echo /tmp/.ansible/tmp/ansible-tmp-1543139945.24-52208136278646 \" && echo ansible-tmp-1543139945.24-52208136278646=\" echo /tmp/.ansible/tmp/ansible-tmp-1543139945.24-52208136278646 \" ),退出结果 1 ”,
“无法访问”:true
}

能够使用 ansible 执行 playbook,但在使用 ansible 塔执行相同的 playbook 时出现错误


<192.168.0.17> 为用户建立 SSH 连接:admin
<192.168.0.17> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=admin -o ConnectTimeout=10 -o ControlPath=/tmp/awx_86_9cdeKb/cp/86796477d7 192.168.0.17 '/bin/sh -c '"'"'echo ~admin && sleep 0'"'" ''
<192.168.0.17> (255, '', "Warning: 已将 '192.168.0.17' (ECDSA) 永久添加到已知主机列表中。\r\n权限被拒绝 (publickey,gssapi-keyex,gssapi-with-mic,password) ).\r\n")
致命:[192.168.0.17]:无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机:警告:将“192.168.0.17”(ECDSA) 永久添加到已知主机列表中。\r\n权限被拒绝 (publickey,gssapi-keyex,gssapi-with-mic ,密码).\r\n",“无法访问”:true
}

我有这个问题,请给我解决方案

Ubuntu的@Master:〜$ ansible-剧本playbook2.yml -b PLAY [172.31.42.20] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * TASK [收集事实] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
致命:[172.31.42.20]:无法访问! => {"changed": false, "msg": "无法通过 ssh 连接到主机:权限被拒绝 (publickey,password)。\r\n", "unreachable": true}
要重试,使用:--limit @ /家庭/ Ubuntu的/ playbook2.retry PLAY重点回顾* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

172.31.42.20:ok=0 改变=0 不可达=1 失败=0

我有这个问题,请给我解决方案

Ubuntu的@主:〜$ ansible-剧本playbook2.yml -b PLAY [172.31.42.20] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * TASK [收集事实] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

致命:[172.31.42.20]:无法访问! => {"changed": false, "msg": "无法通过 ssh 连接到主机:权限被拒绝 (publickey,password)。\r\n", "unreachable": true}
要重试,使用:--limit @ /家庭/ Ubuntu的/ playbook2.retry PLAY重点回顾* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
172.31.42.20:ok=0 改变=0 不可达=1 失败=0

我们有两种解决方案:-

password less auth (you can refer google how to generate rsa key )
add ask_pass=true in ancible.cfg file. (This will ask password when you run ansible)

请设置到主机的 SSH 连接并进行测试。
完成后,在 /etc/ansible/hosts 文件中提供正确的主机 IP。
现在要测试 ansible 和来宾机器之间的安全连接,请使用以下命令:
-> ansible -i hosts -u vagrant --ask-pass -m ping all
主机-> 主机文件(提供适当的访客 IP)
-u vagrant -> vagrant 是我的访客机器用户名
--ask-pass-> 它允许您输入 SSH 密码以连接来宾 m/c。
注意:如果我不使用 --ask-pass 它会抛出错误。

如果有帮助,谢谢:)

您的 /etc/ansible/hosts 很可能是错误的

我是 ansible 的新手,谁能帮助我

34.201.109.32 | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机: [email protected] :权限被拒绝(公钥)。\r\n",
“无法访问”:true
}

尝试在 hosts 文件中包含目标机器的密码。
通常,您需要有一个现有的 ssh 连接
为您的主机和本地机器生成一个 RSA 密钥。 尝试 ssh 进入
主机然后再次运行ansible。

2019 年 1 月 20 日,星期日,上午 11:22 Venkata Bhanusree Vadlamudi <
[email protected]> 写道:

我是 ansible 的新手,谁能帮助我

34.201.109.32 | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机: [email protected] :
权限被拒绝(公钥)。\r\n",
“无法访问”:true
}


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/ansible/ansible/issues/19584#issuecomment-455880089
或静音线程
https://github.com/notifications/unsubscribe-auth/An-8H0nPfSdUELQxzoQAvvHHlsau7uyBks5vFJfOgaJpZM4LSWpz
.

当我从本地终端使用 ssh 命令时,我能够连接到 ec2 实例。 但是,当我运行 ansible 脚本时,出现错误。

34.201.109.32 | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机: [email protected] :权限被拒绝(公钥)。\r\n",
“无法访问”:true
}

对于 AWS ec2 实例,您必须通过 AWS 生成公钥,
下载它,并将 ssh 会话指向该密钥。 有教程
这个程序在线。

2019 年 1 月 20 日星期日下午 4:48 Venkata Bhanusree Vadlamudi <
[email protected]> 写道:

当我从本地终端使用 ssh 命令时,我无法连接
到 ec2 实例。 但是,当我运行 ansible 脚本时,出现错误。

34.201.109.32 | 无法访问! => {
“改变”:假,
"msg": "无法通过 ssh 连接到主机: [email protected] :
权限被拒绝(公钥)。\r\n",
“无法访问”:true
}


您收到此消息是因为您发表了评论。
直接回复本邮件,在GitHub上查看
https://github.com/ansible/ansible/issues/19584#issuecomment-455905472
或静音线程
https://github.com/notifications/unsubscribe-auth/An-8Hya_SkLrHT-HLYEOPEE2QXsSuDOJks5vFOQOgaJpZM4LSWpz
.

嗨,伙计们,
我有同样的问题。
我的 devops 用户可以通过 ssh 连接到所有服务器,但是当我尝试运行(使用 mysuer)ansible 命令时,我总是遇到错误......无法访问! ...
我通过使用“mysuer”ssh serverDestiny(库存文件中的服务器)注释解决了这个问题,如果您使用 fqdn,则必须将 ssh 连接到 FQDN。
例子:
猫库存
服务器 1

[ myuser@workstation ansible-deploy-cr] ssh-keygen
[ myuser@workstation ansible-deploy-cr] ssh-copy-id -i devops@server1
测试..
[ myuser@workstation ansible-deploy-cr] ssh ' devops@server1

希望这会帮助你。
如果有,给个赞👍
谢谢,
美布里托

这解决了我在私有 VPC 上的 AWS 问题,我需要所有服务器的内部 fqdn

大家好,
我在 localhost 上遇到了同样的问题,并意识到“$ ssh localhost”要求输入密码。 我通过将本地主机上“用户”的公钥移动到authorized_key来解决它。

ssh-copy-id -i ~/.ssh/id_rsa.pub test@localhost

只需检查authorized_key 文件是否具有必要的密钥

测试是用户名

哇.....我通读了评论。 不敢相信问题仍然存在。 我在最新的ansible。 我想这是使用开源的痛苦之一。

vagrant<strong i="6">@mgmt</strong>:~$ ansible lb -u vagrant -m ping -vvv
ansible 2.7.8
  config file = /home/vagrant/ansible.cfg
  configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
Using /home/vagrant/ansible.cfg as config file
[DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it can also be a list of hosts, a directory or a list of paths , use [defaults] inventory=/path/to/file|dir 
instead. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
/home/vagrant/inventory.ini did not meet host_list requirements, check plugin documentation if this is unexpected
/home/vagrant/inventory.ini did not meet script requirements, check plugin documentation if this is unexpected
/home/vagrant/inventory.ini did not meet yaml requirements, check plugin documentation if this is unexpected
Parsed /home/vagrant/inventory.ini inventory source with ini plugin
 [WARNING]: Found both group and host with same name: lb

META: ran handlers
<lb> ESTABLISH SSH CONNECTION FOR USER: vagrant
<lb> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/2302ac11ec lb '/bin/sh -c '"'"'echo ~vagrant && sleep 0'"'"''
<lb> (255, '', 'Permission denied (publickey).\r\n')
lb | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey).", 
    "unreachable": true
}

解决方案

好吧,这对我有用 -
我登录到远程机器lb 。 编辑 ~/.ssh/authorised_keys 并添加 ansible master 的 id_rsa.pub 密钥。 保存并退出。 在 lb 上弹回 sshd。

这不是一个完美的方法,但它可以让您进行初步测试。

编辑 1 - 此外,您需要确保远程机器(将由 ansible 管理的客户端)需要安装 python。

PS - 即使是 ssh-copy-id -i 的方法对我来说也失败了,同样的权限被拒绝错误(公钥)

vagrant@mgmt :~$ ansible lb -m ping -vvv
安全的 2.7.8
配置文件 = /home/vagrant/ansible.cfg
配置的模块搜索路径 = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python 模块位置 = /usr/lib/python2.7/dist-packages/ansible
可执行位置 = /usr/bin/ansible
python 版本 = 2.7.12(默认,2018 年 11 月 12 日,14:36:49)[GCC 5.4.0 20160609]
使用 /home/vagrant/ansible.cfg 作为配置文件
[DEPRECATION WARNING]: [defaults]hostfile 选项,关键是误导,因为它也可以是主机列表、目录或路径列表,使用 [defaults]inventory=/path/to/file|dir
反而。 此功能将在 2.8 版中删除。 可以通过在 ansible.cfg 中设置 deprecation_warnings=False 来禁用弃用警告。
/home/vagrant/inventory.ini 不符合 host_list 要求,如果这是意外,请检查插件文档
/home/vagrant/inventory.ini 不符合脚本要求,如果这是意外,请检查插件文档
/home/vagrant/inventory.ini 不符合 yaml 要求,如果这是意外,请检查插件文档
使用 ini 插件解析 /home/vagrant/inventory.ini 库存源
[警告]:找到同名的组和主机:lb

META:运行处理程序
为用户建立 SSH 连接:无
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/e51df67eb4 lb '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
(0, '/home/vagrant\n', '')
为用户建立 SSH 连接:无
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/e51df67eb4 lb '/bin/sh -c '"'"'( umask 77 && mkdir -p " echo /home/vagrant/.ansible/tmp/ansible-tmp-1552670816.4-42574892310286 " && echo ansible-tmp-1552670816.4-42574892310286 =" echo /home/vagrant/.ansible/tmp/ansible-tmp-1552670816.4-42574892310286 " ) && 睡眠 0'"'"''
(0, 'ansible-tmp-1552670816.4-42574892310286=/home/vagrant/.ansible/tmp/ansible-tmp-1552670816.4-42574892310286\n', '')
使用模块文件 /usr/lib/python2.7/dist-packages/ansible/modules/system/ping.py
将 /home/vagrant/.ansible/tmp/ansible-local-2173_L8KXK/tmpXoK8R8 放到 /home/vagrant/.ansible/tmp/ansible-tmp-1552670816.4-42574892310286/AnsiballZ_ping。
SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout= 10 -o ControlPath=/home/vagrant/.ansible/cp/e51df67eb4 '[lb]'
(0, 'sftp> put /home/vagrant/.ansible/tmp/ansible-local-2173_L8KXK/tmpXoK8R8 /home/vagrant/.ansible/tmp/ansible-tmp-1552670816.4-42574892310286,'Ansipyn'Ansipyn ')
为用户建立 SSH 连接:无
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/e51df67eb4 lb '/bin/sh -c '"'"'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1552670816.4-42574892310286//home /vagrant/.ansible/tmp/ansible-tmp-1552670816.4-42574892310286/AnsiballZ_ping.py && sleep 0'"'"''
(0, '', '')
为用户建立 SSH 连接:无
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/e51df67eb4 -tt lb '/bin/sh -c '"'"'/usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1552670816.4- 42574892310286/AnsiballZ_ping.py && sleep 0'"'"''
(0, '\r\n{"invocation": {"module_args": {"data": "pong"}}, "ping": "pong"}\r\n', '与 lb 的共享连接已关闭。 \r\n')
为用户建立 SSH 连接:无
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/e51df67eb4 lb '/bin/sh -c '"'"'rm -f -r /home/vagrant/.ansible/tmp/ansible-tmp-1552670816.4-42574892310286/ > /dev/null 2>&1 && sleep 0'"'"''
(0, '', '')
磅 | 成功 => {
“改变”:假,
“调用”:{
“模块参数”:{
“数据”:“乒乓”
}
},
“乒乓”
}

此页面是否有帮助?
0 / 5 - 0 等级