SSH(ssh: connect to host localhost port 22: Connection refused)问题的解决

我们在远程ssh链接ubuntn服务器的时候,会出现一下的一个问题

Copy Highlighter-hljs
ssh: connect to host localhost port 22: Connection refused

之所以出现这个问题,是因为我们ubuntn系统默认是没有安装openssh-server的。

解决办法就是安装这个模块

Copy Highlighter-hljs
sudo apt-get install openssh-server

安装完成后,我们再输入下面的命令,就可以远程登录了

Copy Highlighter-hljs
ssh ubuntu@xx.20.xxx.63

再执行完命令的时候,还会出现一个问题

Copy Highlighter-hljs
➜ ~ ssh ubuntu@xx.20.xxx.63 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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:mPfvt1SS+fncIH5f8DYiFtoII7eLtHdTJ1CbTRYx6oo. Please contact your system administrator. Add correct host key in /Users/用户名/.ssh/known_hosts to get rid of this message. Offending ECDSA key in /Users/用户名/.ssh/known_hosts:6 ECDSA host key for xx.20.xxx.63 has changed and you have requested strict checking. Host key verification failed.

原因:

因为服务器的ip发生变更了
第一次SSH连接时,会生成一个认证,储存在客户端(也就是用SSH连线其他电脑的那个,自己操作的那个)中的known_hosts,但是如果服务器验证过了,认证资讯当然也会更改,服务器端与客户端不同时,就会跳出错误啦。

解决办法:

输入命令:ssh-keygen -R +输入服务器的IP

Copy Highlighter-hljs
~ ssh-keygen -R xx.20.xxx.63 # Host xx.20.xxx.63 found: line 36 /Users/用户名/.ssh/known_hosts updated.

或者

Copy Highlighter-hljs
rm ~/.ssh/known_hosts

上面两个命令执行其中一个之后,在继续执行ssh ubuntu@xx.20.xxx.63

Copy Highlighter-hljs
~ ssh ubuntu@172.20.110.63 The authenticity of host '172.20.110.63 (172.20.110.63)' can't be established. ECDSA key fingerprint is SHA256:mPfvt1SS+fncIH5f8DYiFtoII7eLtHdTJ1CbTRYx6oo. Are you sure you want to continue connecting (yes/no/[fingerprint])?

输入yes

Copy Highlighter-hljs
ubuntu@172.20.110.63's password: [输入密码] Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-107-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage 26 updates can be applied immediately. To see these additional updates run: apt list --upgradable Your Hardware Enablement Stack (HWE) is supported until April 2023. The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. ubuntu@ubuntu-HP-Z4-G4-Workstation:~$ [进入服务器]
posted @   流年中渲染了微笑  阅读(2427)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示