今早连接SSH服务发现报错很诡异;
在这里插入图片描述

从百度上搜索了一堆信息,现在收集整理给大家一些有用的解决方案

1.重新启动CentOS
2.重启VMWare
3.防火墙问题:
解决方案:
(1)查看防火墙:service iptables status
(2)先关闭防火墙:/etc/init.d/iptables stop
(3)打开防火墙: service iptables start
启动: systemctl start firewalld (centos7用户)
关闭: systemctl stop firewalld (centos7用户)
4.查询是否开启22端口

查询所有打开端口命令

  firewall-cmd --zone=public --list-ports

永久开启22端口

  firewall-cmd --zone=public --add-port=80/tcp --permanent 

重新加载

firewall-cmd --reload

5.查询Linux服务器是否安装SSH

yum install openssh-server

6.查询SELINUX是否启动
在/etc/selinux/config文件中如下修改,设置SELINUX=disabled:
在这里插入图片描述
以上是百度收集的一些处理方案,但是和我的问题好像不太匹配;

然后我重新查询SSH服务的时候

systemctl status sshd.service

发现报错了

鈼� sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since 鍥� 2022-03-17 17:46:56 CST; 19s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 4194 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=1/FAILURE)
 Main PID: 4194 (code=exited, status=1/FAILURE)

3鏈� 17 17:46:57 micronview sshd[4194]: Permissions 0737 for '/etc/ssh/ssh_h....
3鏈� 17 17:46:57 micronview sshd[4194]: It is required that your private key....
3鏈� 17 17:46:57 micronview sshd[4194]: This private key will be ignored.
3鏈� 17 17:46:57 micronview sshd[4194]: key_load_private: bad permissions
3鏈� 17 17:46:57 micronview sshd[4194]: Could not load host key: /etc/ssh/ss...y
3鏈� 17 17:46:57 micronview sshd[4194]: sshd: no hostkeys available -- exiting.
3鏈� 17 17:46:56 micronview systemd[1]: sshd.service: main process exited, c...E
3鏈� 17 17:46:56 micronview systemd[1]: Failed to start OpenSSH server daemon.
3鏈� 17 17:46:56 micronview systemd[1]: Unit sshd.service entered failed state.
3鏈� 17 17:46:56 micronview systemd[1]: sshd.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

仔细分析了一下日志(注意看关键词):
Permissions 0737 for '/etc/ssh/ssh_h…
然后查询了一下

/usr/sbin/sshd -T

发现了关键词

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0737 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.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_rsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0737 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.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0737 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.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.

一直显示加载不到ssh_host_ed25519_key 文件还有前边获取状态的时候出现的权限

然后我尝试收回权限

chmod -R 600 /etc/ssh/

重新SSH服务

systemctl status sshd.service

在这里插入图片描述

成功了,也正常的连接到了SSH服务,到现在为止才知道之前给/etc的文件下的权限给的太高了,导致所有人都能读写出现的安全问题。以上就是我此次服务器连不上问题的解决方案,总有一款能解决你的问题。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐