今天用SecureCRT遠程連接Linux(Centos 7)時,連不上,報錯The remote system refused the connection.
於是就百度,首先查看sshd服務有沒有啟動

只有ssh-agent,於是去啟動sshd
執行如下命令
cd /etc/init.d
systemctl restart sshd.service
沒有成功,報錯
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
。
再使用這個命令journalctl -xe
看錯誤信息,具體報錯信息如下。
[root@localhost ssh]# systemctl restart sshd.service
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
[root@localhost ssh]# journalctl -xe
12月 05 10:45:01 localhost.localdomain sshd[11508]: Permissions 0715 for '/etc/ssh/ssh_host_rsa_key' are too open.
12月 05 10:45:01 localhost.localdomain sshd[11508]: It is required that your private key files are NOT accessible by others.
12月 05 10:45:01 localhost.localdomain sshd[11508]: This private key will be ignored.
12月 05 10:45:01 localhost.localdomain sshd[11508]: key_load_private: bad permissions
12月 05 10:45:01 localhost.localdomain sshd[11508]: Could not load host key: /etc/ssh/ssh_host_rsa_key
12月 05 10:45:01 localhost.localdomain sshd[11508]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
12月 05 10:45:01 localhost.localdomain sshd[11508]: @ WARNING: UNPROTECTED PRIVATE KEY FILE! @
12月 05 10:45:01 localhost.localdomain sshd[11508]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
12月 05 10:45:01 localhost.localdomain sshd[11508]: Permissions 0715 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
12月 05 10:45:01 localhost.localdomain sshd[11508]: It is required that your private key files are NOT accessible by others.
12月 05 10:45:01 localhost.localdomain sshd[11508]: This private key will be ignored.
12月 05 10:45:01 localhost.localdomain sshd[11508]: key_load_private: bad permissions
12月 05 10:45:01 localhost.localdomain sshd[11508]: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
12月 05 10:45:01 localhost.localdomain systemd[1]: sshd.service: main process exited, code=exited, status=1/FAILURE
12月 05 10:45:01 localhost.localdomain sshd[11508]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
12月 05 10:45:01 localhost.localdomain sshd[11508]: @ WARNING: UNPROTECTED PRIVATE KEY FILE! @
12月 05 10:45:01 localhost.localdomain sshd[11508]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
12月 05 10:45:01 localhost.localdomain sshd[11508]: Permissions 0715 for '/etc/ssh/ssh_host_ed25519_key' are too open.
12月 05 10:45:01 localhost.localdomain sshd[11508]: It is required that your private key files are NOT accessible by others.
12月 05 10:45:01 localhost.localdomain sshd[11508]: This private key will be ignored.
12月 05 10:45:01 localhost.localdomain sshd[11508]: key_load_private: bad permissions
12月 05 10:45:01 localhost.localdomain sshd[11508]: Could not load host key: /etc/ssh/ssh_host_ed25519_key
12月 05 10:45:01 localhost.localdomain sshd[11508]: sshd: no hostkeys available -- exiting.
12月 05 10:45:01 localhost.localdomain systemd[1]: Failed to start OpenSSH server daemon.
-- Subject: Unit sshd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sshd.service has failed.
--
-- The result is failed.
12月 05 10:45:01 localhost.localdomain systemd[1]: Unit sshd.service entered failed state.
12月 05 10:45:01 localhost.localdomain systemd[1]: sshd.service failed.
12月 05 10:45:01 localhost.localdomain polkitd[7760]: Unregistered Authentication Agent for unix-process:11502:197209 (system bus name :1.14
lines 1492-1525/1525 (END)
看到很多Permissions
這個詞,權限。
諸如;Permissions 0715 for '/etc/ssh/ssh_host_rsa_key' are too open.
key_load_private: bad permissions
的錯,這是一些密鑰文件,也就是說沒有權限訪問這幾個文件,可我用的root啊也沒權限,奇怪了。
那么我們看看這三個文件現在的權限是什么。切到/etc/ssh
下ll
查看,這三個文件的權限是755,感覺沒啥問題啊。繼續百度吧。

搜了好久,有篇博文說執行這個命令
chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key
也就是修改這個三個文件的權限為600
再執行systemctl restart sshd.service
重啟sshd服務
再查看是否啟動,果然起來了。

再用SecureCRT連接就連上了。
太曲折了。期間還執行了sudo yum install openssh-server
安裝ssh服務,修改了ifcfg-eth0,centos沒有這個文件只有ifcfg-ens33,不知有用沒,還有查看端口的、/etc/ssh/sshd_config文件的Post是不是22等等。最后終於解決了。