XShell远程连接CentOS7自动断开解决方案

问题

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秒:
在这里插入图片描述

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值