ssh 提示Connection closed by * 的解决方案

/*********************************************************************
* Author          :     lile
* Modified        :     2019年12月28日星期六  10:56:13
* Email           :     roger0212@163.com
* HomePage        :     lile777.blog.csdn.net
* CopyRight       :     该文章版权由lile所有。
*                       保留原文出处链接和本声明的前提下,可在非商业目的下任意传播和复制。
*                       对于商业目的下对本文的任何行为需经作者同意。
*********************************************************************/



查看ssh服务端的日志
ubuntu@tegra-ubuntu:~$ cat /var/log/auth.log
Jun 20 16:55:26 tegra-ubuntu sshd[1192]: Server listening on 0.0.0.0 port 22.
Jun 20 16:55:26 tegra-ubuntu sshd[1192]: Server listening on :: port 22.
Jun 20 16:55:27 tegra-ubuntu login[1313]: pam_unix(login:session): session opened for user ubuntu by LOGIN(uid=0)
Jun 20 16:55:28 tegra-ubuntu lightdm: pam_unix(lightdm-autologin:session): session opened for user ubuntu by (uid=0)
Jun 20 16:55:31 tegra-ubuntu polkitd(authority=local): Registered Authentication Agent for unix-session:c2 (system bus name :1.60 [/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1], object path /org/gnome/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Jun 20 16:56:16 tegra-ubuntu sshd[2145]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Jun 20 16:56:16 tegra-ubuntu sshd[2145]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Jun 20 16:56:16 tegra-ubuntu sshd[2145]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Jun 20 16:56:16 tegra-ubuntu sshd[2145]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
Jun 20 16:56:16 tegra-ubuntu sshd[2145]: fatal: No supported key exchange algorithms [preauth]
ubuntu@tegra-ubuntu:~$ 


ubuntu@tegra-ubuntu:~$ ll /etc/ssh 
total 268
drwxr-xr-x   2 root root   4096 Jan  1  1970 ./
drwxr-xr-x 133 root root  12288 Jun 20 16:55 ../
-rw-r--r--   1 root root 242091 Apr  2  2015 moduli
-rw-r--r--   1 root root   1690 Apr  2  2015 ssh_config
-rw-r--r--   1 root root   2541 Apr  2  2015 sshd_config
-rw-------   1 root root      0 Jan  1  1970 ssh_host_dsa_key
-rw-r--r--   1 root root      0 Jan  1  1970 ssh_host_dsa_key.pub
-rw-------   1 root root      0 Jan  1  1970 ssh_host_ecdsa_key
-rw-r--r--   1 root root      0 Jan  1  1970 ssh_host_ecdsa_key.pub
-rw-------   1 root root      0 Jan  1  1970 ssh_host_rsa_key
-rw-r--r--   1 root root      0 Jan  1  1970 ssh_host_rsa_key.pub
-rw-r--r--   1 root root    338 Apr  2  2015 ssh_import_id
ubuntu@tegra-ubuntu:~$ 

重新生成密钥
sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key 


ubuntu@tegra-ubuntu:~$ ll /etc/ssh 
total 292
drwxr-xr-x   2 root root   4096 Jan  1  1970 ./
drwxr-xr-x 133 root root  12288 Jun 20 16:59 ../
-rw-r--r--   1 root root 242091 Apr  2  2015 moduli
-rw-r--r--   1 root root   1690 Apr  2  2015 ssh_config
-rw-r--r--   1 root root   2541 Apr  2  2015 sshd_config
-rw-------   1 root root    668 Jan  1  1970 ssh_host_dsa_key
-rw-r--r--   1 root root    607 Jan  1  1970 ssh_host_dsa_key.pub
-rw-------   1 root root    227 Jan  1  1970 ssh_host_ecdsa_key
-rw-r--r--   1 root root    179 Jan  1  1970 ssh_host_ecdsa_key.pub
-rw-------   1 root root   1679 Jan  1  1970 ssh_host_rsa_key
-rw-r--r--   1 root root    399 Jan  1  1970 ssh_host_rsa_key.pub
-rw-r--r--   1 root root    338 Apr  2  2015 ssh_import_id
ubuntu@tegra-ubuntu:~$ 


客户端重新登录,提示 
roger@ubuntu:~$ ssh ubuntu@192.168.0.224
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the DSA key sent by the remote host is
89:5a:d2:79:cc:66:7c:5e:dd:64:ef:05:dd:83:25:e1.
Please contact your system administrator.
Add correct host key in /home/roger/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/roger/.ssh/known_hosts:2
  remove with: ssh-keygen -f "/home/roger/.ssh/known_hosts" -R 192.168.0.224
DSA host key for 192.168.0.224 has changed and you have requested strict checking.
Host key verification failed.

清除当前的密钥
roger@ubuntu:~$ ssh-keygen -f "/home/roger/.ssh/known_hosts" -R 192.168.0.224
# Host 192.168.0.224 found: line 2 type ECDSA
/home/roger/.ssh/known_hosts updated.
Original contents retained as /home/roger/.ssh/known_hosts.old
roger@ubuntu:~$

重新登录即可 
roger@ubuntu:~$ ssh ubuntu@192.168.0.224
The authenticity of host '192.168.0.224 (192.168.0.224)' can't be established.
DSA key fingerprint is 89:5a:d2:79: 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值