我们在远程ssh链接ubuntn服务器的时候,会出现一下的一个问题
ssh: connect to host localhost port 22: Connection refused
之所以出现这个问题,是因为我们ubuntn系统默认是没有安装openssh-server
的。
解决办法就是安装这个模块
sudo apt-get install openssh-server
安装完成后,我们再输入下面的命令,就可以远程登录了
ssh ubuntu@xx.20.xxx.63
再执行完命令的时候,还会出现一个问题
➜ ~ 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
~ ssh-keygen -R xx.20.xxx.63
# Host xx.20.xxx.63 found: line 36
/Users/用户名/.ssh/known_hosts updated.
或者
rm ~/.ssh/known_hosts
上面两个命令执行其中一个之后,在继续执行ssh ubuntu@xx.20.xxx.63
~ 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
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:~$ [进入服务器]