Ubuntu 密钥交换算法

Ubuntu 密钥交换算法

我正在尝试使用安装在 Ubuntu 20.04.2 LTS 上的 Ansible 和 ansible ad-hoc 测试与多个网络设备的连接。

问题:SSH 无法工作,因为设备的密钥交换方法只有 ssh-RSA,服务器不支持该方法。尝试强制使用 ssh-RSA,但我知道它不可用,因为它不是作为密码协商中的密钥交换方法之一发送的。

Ansible_输出:

    (venv) omera@sandbox:~/code/ansible/play_06$ ansible all -m ping
edge_02 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Unable to negotiate with 192.168.1.201 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1",
    "unreachable": true
}
edge_01 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Unable to negotiate with 192.168.1.200 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1",
    "unreachable": true
}
core_01 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Unable to negotiate with 192.168.1.202 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1",
    "unreachable": true

edge_02_debug_输出:

Edge_02#

    *Jun  7 07:49:14.738: SSH0: starting SSH control process
    *Jun  7 07:49:14.738: SSH0: sent protocol version id SSH-1.99-Cisco-1.25
    *Jun  7 07:49:14.741: SSH0: protocol version id is - SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
    *Jun  7 07:49:14.741: SSH2 0: Server certificate trustpoint not found. Skipping hostkey algo = x509v3-ssh-rsa
    *Jun  7 07:49:14.741: SSH2 0: kexinit sent: hostkey algo = ssh-rsa
    *Jun  7 07:49:14.741: SSH2 0: kexinit sent: encryption algo = aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
    *Jun  7 07:49:14.741: SSH2 0: kexinit sent: mac algo = hmac-sha1,hmac-sha1-96
    *Jun  7 07:49:14.741: SSH2 0: SSH2_MSG_KEXINIT sent
    *Jun  7 07:49:14.741: SSH2 0: SSH2_MSG_KEXINIT received
    *Jun  7 07:49:14.741: SSH2 0: kex: client->server enc:aes128-ctr mac:hmac-sha1 
    *Jun  7 07:49:14.741: SSH2 0: kex: server->client enc:aes128-ctr mac:hmac-sha1 
    *Jun  7 07:49:14.741: %SSH-3-NO_MATCH: No matching kex algorithm found: client curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c server diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

我担心的是是否可以在 ubuntu 上将 RSA 设置为密钥交换方法(ansible 使用 sshpass)?

ii  sshpass  1.06-1   amd64  Non-interactive ssh password authentication

答案1

ansible 默认使用 OpenSSH,它对较旧的 IOS 版本有点挑剔。您必须在 ~/.ssh/config 中启用 Diffie–Hellman 密钥交换和一些较旧的密码。

KexAlgorithms +diffie-hellman-group1-sha1
Ciphers +aes256-cbc,aes192-cbc,aes128-cbc,3des-cbc

或者,您可以尝试使用 paramiko 进行运输。

[defaults]
inventory = /root/hosts
host_key_checking=False
timeout = 30
transport = paramiko

虽然这些说明通常适用于 IOS,但我确信您在 IOU 设备上也遇到了类似的问题。

来源

相关内容