今天在堡垒机上添加资产的时候,一直连接不上,

调试信息里提示:

UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh_exchange_identification: read: Connection reset by peer", "unreachable": true}

在本地通过SSH客户端是可以连接的。

于是,登录到JumpServer上,通过debug命令行连接,果然连接不通。

ssh -v root@xxx.xxx.xxx.xxx

返回的日志信息

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 58: Applying options for * debug1: Connecting to xxxx] port 22. debug1: Connection established. debug1: permanently_set_uid: 0/0 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_rsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_7.4 ssh_exchange_identification: read: Connection reset by peer

应该是目标主机被限制了

解决办法:

在目标主机上

vi /etc/hosts.allow

然后在文件里添加

sshd: JUMPSERVER的IP地址:allow

当然如果你需要允许所有主机访问,可以设置为

sshd:ALL

最后,重启sshd服务即可

service sshd restart