使用xshell连接虚拟机中新安装的centos出现问题
在这里插入图片描述
错误提示说明连接被主机关闭,解决问题先要确定原因,先到虚拟机中看看原因使用命令
systemctl status sshd 查看一下ssh服务运行状态,确定错误原因没有相关密匙文件。

#systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-12-04 14:12:34 CST; 1min 37s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 43493 ExecStart=/usr/sbin/sshd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 43496 (sshd)
   CGroup: /system.slice/sshd.service
           └─43496 /usr/sbin/sshd

Dec 04 14:14:02 localhost.localdomain sshd[43535]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Dec 04 14:14:02 localhost.localdomain sshd[43535]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Dec 04 14:14:02 localhost.localdomain sshd[43535]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Dec 04 14:14:02 localhost.localdomain sshd[43535]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
Dec 04 14:14:02 localhost.localdomain sshd[43535]: fatal: No supported key exchange algorithms [preauth]
Dec 04 14:14:08 localhost.localdomain sshd[43545]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Dec 04 14:14:08 localhost.localdomain sshd[43545]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Dec 04 14:14:08 localhost.localdomain sshd[43545]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Dec 04 14:14:08 localhost.localdomain sshd[43545]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
Dec 04 14:14:08 localhost.localdomain sshd[43545]: fatal: No supported key exchange algorithms [preauth]

经过查询资料了解到此密匙文件可以使用手动生成,但本人对ssh并不十分了解决定不使用此方法。
既然系统原带的ssh服务有问题,那么就重新安装ssh

重装ssh服务

1、卸载yum remove openssh*
2、安装yum install openssh-server
3、查看是否安装成功rpm -qa openssh*
4、启动服务systemctl start sshd
5、设置开机自自动systemctl enable sshd
6、查看状态 systemctl status sshd,发现已经没有相关错误
7、使用Xshell重新连接连接成功
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201204144538907.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L25ld2JpZUxDUQ==,size_16,color_FFFFFF,t_70

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐