1. SSH 登录命令是 ssh 主机名@192.168.x.xxx
正常情况下是可以登录的
2. 但是有的情况下远程登录的时候会出现这样的错误提示:
The authenticity of host ‘192.168.43.100 (192.168.43.100)’ can’t be established.
ECDSA key fingerprint is SHA256:IoAgrDFGF+o1CyU+12i4N6FZgUPrW/ZvPFnY24kUKQ4.
Are you sure you want to continue connecting (yes/no)?
可能因为本地端变更密钥了,造成报错
3. 这时可以使用ssh -o StrictHostKeyChecking=no 主机名@192.168.x.xxx,来登录
4. 登录的时候也有这种报错的:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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:35YzN6jRhr602nOkNeWywbNE7WUPVQ1xl9HJRSSTpsU.
Please contact your system administrator.
Add correct host key in /home/yhai/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/yhai/.ssh/known_hosts:1
remove with:
ssh-keygen -f “/home/yhai/.ssh/known_hosts” -R “192.168.43.100”
ECDSA host key for 192.168.43.100 has changed and you have requested strict checking.
Host key verification failed.
5. 遇到这种报错,方法3是行之无效的,只能删除本地.ssh文件,然后采用方法3才可以
//====================================================================================//
毕竟使用密码登录还是烦的要命,接下来使用免密登录方法:
1. 制作公钥,但是在制作公钥之前要将原来的文件备份一下:mv .ssh .ssh.bak,防止损坏无法恢复
2. 执行:ssh-keygen,完了以后敲3个回车即可生成.ssh目录,目录下自动生成id_rsa.pub文件,这个文件就是公钥文件
3. 既然主机已经重新生成了公钥文件,那么即使之前能ssh登录的远程端现在反而登不上去了,因为密钥不对称了
这时候就要另外开启一个控制台执行ssh -o StrictHostKeyChecking=no 主机名@192.168.x.xxx,来强行打通远程端
4. 接下来,将生成的公钥文件id_rsa.pub拷贝到需要远程登录的主机家目录下:ssh-copy-id -i .ssh/id_rsa.pub 主机名@192.168.xxx.xxx
5. 这时会提示你输入远程端的密码:
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “.ssh/id_rsa.pub”
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
ywd@192.168.43.100’s password:
6. 输入完成后就会出现:
Now try logging into the machine, with: “ssh ‘ywd@192.168.43.100′”
and check to make sure that only the key(s) you wanted were added.
代表可以免密登录了