问题
XShell连接报错信息如下:
Connecting to 192.168.0.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(192.168.0.100) at 12:22:36.
解决方案
情况1:IP冲突
ip冲突导致,修改ip即可。
情况2:ssh相关文件权限问题(也是我的情况)
"/etc/ssh"
目录下ssh相关文件权限问题导致。
相关文件权限配置应当如下:
[root@lee000 ssh]# ll
total 276
-rw-r--r--. 1 root root 242153 Mar 6 2015 moduli
-rw-r--r--. 1 root root 2208 Mar 6 2015 ssh_config
-rw-------. 1 root root 4362 Feb 17 11:30 sshd_config
-rwx------. 1 root ssh_keys 227 Nov 24 23:14 ssh_host_ecdsa_key
-rw-r--r--. 1 root root 162 Nov 24 23:14 ssh_host_ecdsa_key.pub
-rwx------. 1 root ssh_keys 387 Nov 24 23:14 ssh_host_ed25519_key
-rw-r--r--. 1 root root 82 Nov 24 23:14 ssh_host_ed25519_key.pub
-rwx------. 1 root ssh_keys 1679 Nov 24 23:14 ssh_host_rsa_key
-rw-r--r--. 1 root root 382 Nov 24 23:14 ssh_host_rsa_key.pub
否则会报如下错误:
[root@lee000 ssh]# sshd -t
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0604 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_rsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0604 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0604 for '/etc/ssh/ssh_host_ed25519_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /etc/ssh/ssh_host_ed25519_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
这是因为密钥文件权限太开放了,要求密钥文件不能有被其它用户读取的权限。此情况解决方案就是将警告的文件修改权限为700即可:
[root@lee000 ssh]# chmod 700 /etc/ssh/ssh_host_ecdsa_key
[root@lee000 ssh]# chmod 700 /etc/ssh/ssh_host_ed25519_key
[root@lee000 ssh]# chmod 700 /etc/ssh/ssh_host_rsa_key
检验。再次输入命令"sshd -t",无任何提示后重启下sshd即可:
systemctl restart sshd
情况3:SSH连接超时
服务器端配置:
vim /etc/ssh/sshd_config
放开以下参数(删除#
号)并设值:
ClientAliveInterval 60
ClientAliveCountMax 3
“ClientAliveInterval”
用来指定服务器向客户端发送消息的时间间隔。默认是0,即不发送。
“ClientAliveCountMax”
用来指定服务器向客户端发送消息的次数。若达到指定次数,客户端没有回复,那么连接就要断开。
设置完成后重启sshd服务:
service sshd restart
或者
/etc/init.d/sshd restart
客户端配置
如果服务器端配置无效的话,可以尝试客户端配置,本人就是服务器端配置没效果
路径:文件 --> 默认会话属性 --> 连接 --> 保持活动状态
“连接会话期间发送保持活动状态消息间隔” 设置为20秒: