且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

记录问题:SSH无法连接问题: java.io.IOException: End of IO Stream Read

更新时间:2021-07-06 21:05:01

一、问题排查

最近在开发中连接SSH报错
使用finalshell报错:

Session.connect: java.io.IOException: End of IO Stream Read

使用SecureCRT报错:

Connection reset by 172.20.28.31 port 22

使用telnet查看22端口正常

telnet 172.20.28.31 22
SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.10

由于使用的是虚机,登录虚机后台控制台查看ssh运行情况

netstat -tunlp|grep 22

返回正常:
记录问题:SSH无法连接问题: java.io.IOException: End of IO Stream Read

在网上查找半天,终于在[[mcj]FinalShell无法连接ssh:Session.connect: java.io.IOException: End of IO Stream Read-马春杰杰 (machunjie.com)](https://www.machunjie.com/linux/122.html) 找到了解决方案。

使用 sshd -t 进程测试:
注:测试模式。仅检查配置文件的有效性和密钥的合理性。这适用于在配置选项可能发生更改时可靠地更新 sshd。
记录问题:SSH无法连接问题: java.io.IOException: End of IO Stream Read

it is required that your private key files are not accessible by others
this private key will be ignored
其他人不能访问私钥文件
此私钥将被忽略
需要修改这些私钥的权限

二、问题解决

使用下面的命令:修改对应权限

chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_dsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key

重启ssh生效,即可连接。

三、参考资料

[[mcj]FinalShell无法连接ssh:Session.connect: java.io.IOException: End of IO Stream Read-马春杰杰 (machunjie.com) ](https://www.machunjie.com/linux/122.html)