今天有台服务器中的某个容器突然无法进行ssh连接,师弟用Xshell连接提示:
1 |
Connection closing...Socket close.Connection closed by foreign host.Disconnected from remote host(localhost) at xxx |
我这边用FinalShell测试的,提示:
1 |
Session.connect: java.io.IOException: End of IO Stream Read |
一开始以为是jdk版本太低,一般升为1.8即可解决,不过我查看了jdk的版本,已经是1.8了,故排除此项。
后来猜想是不是OpenSSH安装的有问题?于是卸载重装仍然没有解决。
突然想到会不会是ssh文件的问题?
在root账户下打开ssh测试模式:
1 |
sshd -t |
结果提示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0660 for '/etc/ssh_host_rsa_key' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored. key_load_private: bad permissions Could not load host key: /etc/ssh_host_rsa_key @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0660 for '/etc/ssh_host_dsa_key' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored. key_load_private: bad permissions Could not load host key: /etc/ssh_host_dsa_key @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0660 for '/etc/ssh_host_ecdsa_key' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored. key_load_private: bad permissions Could not load host key: /etc/ssh_host_ecdsa_key @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0660 for '/etc/ssh_host_ed25519_key' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored. key_load_private: bad permissions Could not load host key: /etc/ssh_host_ed25519_key Disabling protocol version 2. Could not load host key sshd: no hostkeys available -- exiting. |
看来问题出在这里了,ssh相关文件权限太大,这个好办,我们把所有涉及到的文件的权限全部改为600即可。顺利解决~
修改SSH端口
ssh-server配置文件位于/ etc/ssh/sshd_config,打开此文件,默认端口为22,我们直接修改为想要的端口即可,修改之后重新启动ssh服务。
1 |
sudo /etc/init.d/ssh restart |
附SSHD命令大全:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
选项 -4:强制使用IPv4地址; -6:强制使用IPv6地址; -D:以后台守护进程方式运行服务器; -d:调试模式; -e:将错误发送到标准错误设备,而不是将其发送到系统日志; -f:指定服务器的配置文件; -g:指定客户端登录时的过期时间,如果在此期限内,用户没有正确认证,则服务器断开次客户端的连接; -h:指定读取主机key文件; -i:ssh以inetd方式运行; -o:指定ssh的配置选项; -p:静默模式,没有任何信息写入日志; -t:测试模式。 |
本文最后更新于2023年1月8日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!