SSH验证问题
今天重置阿里云服务器,用ssh连服务器,发现连不上,防火墙也打开了,猜测服务器没有开启ssh
服务器开启ssh步骤
-
要确保CentOS7安装了
openssh-server
,在终端中输入yum list installed | grep openssh-server
-
如果又没任何输出显示表示没有安装
openssh-server
,通过输入yum install openssh-server
-
找到了
/etc/ssh/
目录下的sshd服务配置文件sshd_config
-
将文件中,关于
监听端口
、监听地址
前的 # 号去除 -
允许远程登录
-
开启使用用户名密码来作为连接验证
-
开启
sshd
服务,输入sudo service sshd start
-
检查
sshd
服务是否已经开启,输入ps -e | grep sshd
-
为了免去每次开启 CentOS 时,都要手动开启 sshd 服务,可以将 sshd 服务添加至自启动列表中,输入
systemctl enable sshd.service
问题没有解决
依然显示下面的错误信息
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 ECDSA key sent by the remote host is
SHA256:2L07YcXwuh6amZNAPzR57bjlfrSvgbOEmfCj2jZ4kC4.
Please contact your system administrator.
Add correct host key in /Users/bytedance/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/bytedance/.ssh/known_hosts:14
Host key for 47.103.7.20 has changed and you have requested strict checking.
Host key verification failed.
最终解决方式
ssh-keygen -R "your server hostname or ip"
原因:因为系统有改变,导致加密的密钥改变,因此本地保存的密钥失效;
更具体的原因(参考:ssh权威指南)
总结:服务器会将自己的主机秘钥的一部分在第一次连接时交给客户端保存,用于以后验证服务端的身份,这个主机秘钥就保存在konwn_hosts
中,这么做得目的是为了防止如果后续ssh连接时有中间人攻击的话,能够及时发现。
我重置服务器后,导致主机秘钥发生改变,导致客户端是服务器身份的验证失败,引发上面的原因