首页 > 系统相关 >ubuntu 解决scp ssh登录WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

ubuntu 解决scp ssh登录WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

时间:2024-09-24 13:22:59浏览次数:1  
标签:REMOTE no CHANGED HOST hosts ssh key known root


 

使用SSH登录某台机器,有时因为server端的一些变动,会出现以下信息:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
50:e6:cb:58:bc:b7:a3:f6:e8:8f:46:a7:c1:5f:c2:df.
Please contact your system administrator.
Add correct host key in /home/cobyeah/.ssh/known_hosts to get rid of this message.
Offending key in /home/cobyeah/.ssh/known_hosts:7
RSA host key for 192.168.0.4 has changed and you have requested strict checking.
Host key verification failed.

(此处先不提及原理,只讲处理方法,需要了解原因的请留言或找其他资料)

这时候的处理方法,有3种:
1. 删除提示信息中,对应的行数,例如上例,需要删除/home/cobyeah/.ssh/known_hosts文件的第7行。

2. 删除整份/home/cobyeah/.ssh/known_hosts文件。

3. 修改/etc/ssh/ssh_config文件的配置,以后则不会再出现此问题

StrictHostKeyChecking no
UserKnownHostsFile /dev/null

 输入以下命令重启SSH服务:sudo /etc/init.d/ssh restart

 

root@blj-pc:/etc/ssh# ls
moduli      ssh_config.d  sshd_config.d       ssh_host_ecdsa_key.pub  ssh_host_ed25519_key.pub  ssh_host_rsa_key.pub
ssh_config  sshd_config   ssh_host_ecdsa_key  ssh_host_ed25519_key    ssh_host_rsa_key          ssh_import_id
root@blj-pc:/etc/ssh# cd 
root@blj-pc:~# cd /root/.ssh/
root@blj-pc:~/.ssh# ls
known_hosts  known_hosts.old
root@blj-pc:~/.ssh# rm known_hosts
root@blj-pc:~/.ssh# ls
known_hosts.old
root@blj-pc:~/.ssh# rm -rf *
root@blj-pc:~/.ssh# sudo /etc/init.d/ssh restart
Restarting ssh (via systemctl): ssh.service.
root@blj-pc:~/.ssh# cd /etc/ssh/
root@blj-pc:/etc/ssh# cat ssh_config

# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Include /etc/ssh/ssh_config.d/*.conf

Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,[email protected]
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
root@blj-pc:/etc/ssh# 
View Code

 

下面简单讲一下这个问题的原理和比较长久的解决方案。
用OpenSSH的人都知ssh会把你每个你访问过计算机的公钥(public key)都记录在~/.ssh/known_hosts。当下次访问相同计算机时,OpenSSH会核对公钥。如果公钥不同,OpenSSH会发出警告, 避免你受到DNS Hijack之类的攻击。
SSH对主机的public_key的检查等级是根据StrictHostKeyChecking变量来配置的。默认情况下,StrictHostKeyChecking=ask。简单所下它的三种配置值:
1.
StrictHostKeyChecking=no  
#最不安全的级别,当然也没有那么多烦人的提示了,相对安全的内网测试时建议使用。如果连接server的key在本地不存在,那么就自动添加到文件中(默认是known_hosts),并且给出一个警告。
2.
StrictHostKeyChecking=ask  #默认的级别,就是出现刚才的提示了。如果连接和key不匹配,给出提示,并拒绝登录。
3.
StrictHostKeyChecking=yes  #最安全的级别,如果连接与key不匹配,就拒绝连接,不会提示详细信息。

对于我来说,在内网的进行的一些测试,为了方便,选择最低的安全级别。在.ssh/config(或者/etc/ssh/ssh_config)中配置:

 

StrictHostKeyChecking no
UserKnownHostsFile /dev/null

 

 

 

(注:这里为了简便,将knownhostfile设为/dev/null,就不保存在known_hosts中了)

 

 

 

SSH 登录失败:Host key verification failed 的处理方法

问题1:
SSH 登录失败:Host key verification failed
######################################
由于公钥不一样了,所以无法登录,提示信息是 KEY 验证失败。
解决方法是:
在 /root/.ssh/known_hosts 文件里面将原来的公钥信息删除即可。

SSH 报 “Host key verification failed.”。一般来说,出现该错误有这么几种可能:

1. .ssh/known_hosts 裡面记录的目标主机 key 值不正确。这是最普遍的情况,只要删除对应的主机记录就能恢复正常。

运行命令: sudo rm /home/yourname/.ssh/known_hosts


2. .ssh 目录或者 .ssh/known_hosts 对当前用户的权限设置不正确。这种情况比较少,一般正确设置读写权限以后也能恢复正常。
3. /dev/tty 对 other 用户没有放开读写权限。这种情况极为罕见。出现的现象是,只有 root 用户能够使用 ssh client,而所有其他的普通用户都会出现错误。
我今天遇到的就是第三种情况,修改 /dev/tty 的权限后,一切正常。为了避免以后忘记解决方法,记录在这里。

问题2:
ssh_exchange_identification: Connection closed by remote host
##################################################
解决办法:
修改/etc/hosts.allow文件,加入 sshd:ALL。

符相关配制说明: vi /etc/ssh/ssh_config
-------------------------------------------------
下面逐行说明上面的选项设置:
Host * :选项“Host”只对能够匹配后面字串的计算机有效。“*”表示所有的计算机。 
ForwardAgent no :“ForwardAgent”设置连接是否经过验证代理(如果存在)转发给远程计算机。 
ForwardX11 no :“ForwardX11”设置X11连接是否被自动重定向到安全的通道和显示集(DISPLAY set)。 
RhostsAuthentication no :“RhostsAuthentication”设置是否使用基于rhosts的安全验证。 
RhostsRSAAuthentication no :“RhostsRSAAuthentication”设置是否使用用RSA算法的基于rhosts的安全验证。 
RSAAuthentication yes :RSAAuthentication”设置是否使用RSA算法进行安全验证。 
PasswordAuthentication yes :“PasswordAuthentication”设置是否使用口令验证。 
FallBackToRsh no:“FallBackToRsh”设置如果用ssh连接出现错误是否自动使用rsh。 
UseRsh no :“UseRsh”设置是否在这台计算机上使用“rlogin/rsh”。 
BatchMode no :“BatchMode”如果设为“yes”,passphrase/password(交互式输入口令)的提示将被禁止。当不能交互式输入口令的时候,这个选项对脚本文件和批处理任务十分有用。 
CheckHostIP yes :“CheckHostIP”设置ssh是否查看连接到服务器的主机的IP地址以防止DNS欺骗。建议设置为“yes”。 
StrictHostKeyChecking no :“StrictHostKeyChecking”如果设置成“yes”,ssh就不会自动把计算机 的密匙加入“$HOME/.ssh/known_hosts”文件,并且一旦计算机的密匙发生了变化,就拒绝连接。 
IdentityFile ~/.ssh/identity :“IdentityFile”设置从哪个文件读取用户的RSA安全验证标识。 
Port 22 :“Port”设置连接到远程主机的端口。 
Cipher blowfish :“Cipher”设置加密用的密码。 
EscapeChar ~ :“EscapeChar”设置escape字符。

 

标签:REMOTE,no,CHANGED,HOST,hosts,ssh,key,known,root
From: https://www.cnblogs.com/blj28/p/18428961

相关文章

  • mysql8版本将用户host中的localhost不小心改掉后解决的办法
    在昨天因为某些原因需要给其他外部ip连接我的mysql,所以就上网找了怎么办,找到的办法是将host中localhost改成'%',这确实是可行的。但是由于本人小脑一抽决定先改成其他的试一试,后果就是直接gg,直接报错没有权限无法连接了(由于本人已经解决这个问题了,没有图放了)。下面来说一下解......
  • Windows修改host
    修改host以管理员身份打开以下文件:Windows系统:C:\Windows\System32\drivers\etc\hosts修改:#Copyright(c)1993-2009MicrosoftCorp.##ThisisasampleHOSTSfileusedbyMicrosoftTCP/IPforWindows.##ThisfilecontainsthemappingsofIPaddressestohost......
  • qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed加
    qDebug()<<"QSslSocket="<<QSslSocket::sslLibraryBuildVersionString();qDebug()<<"OpenSSL支持情况:"<<QSslSocket::supportsSsl();打印需要的版本和当前openssl的支持情况如果显示false,不支持就是说明,不支持加密对应下载版本的openssl进行重新编译即可原因......
  • windows10事件代码1074自动重启进程 C:\WINDOWS\system32\svchost.exe用户 NT AUTH
    PSC:\WINDOWS\system32>Get-Eventlog-LogNameSystem-Source"User32"-Newest1|Where-Object{$_.EventID-eq1074}|fl*EventID:1074MachineName:DESKTOP-4COHMG5Data:{}Index:5515......
  • 变化检测从 Angular zonejs) 到 Angular (provideExperimentalZonelessChangeDetectio
    更改检测是angular的一个基本方面,负责识别和更新dom中因数据修改或用户交互而发生更改的部分。此过程可确保ui与底层数据保持一致,从而增强用户体验和应用程序性能。zone.js的作用从历史上看,angular一直依赖zone.js来实现其变更检测机制。zone.js是一个拦截异步......
  • docker阶段03 docker容器内hosts文件, DNS, 查docker空间占用, 部署自动化运维平台spu
    容器内部的hosts文件容器会自动将容器的ID加入自已的/etc/hosts文件中,并解析成容器的IP范例:修改容器的hosts文件[root@ubuntu1804~]#dockerrun-it--rm--add-hostwww.wangxiaochun.com:6.6.6.6--add-hostwww.wang.org:8.8.8.8busybox/#cat/etc/hosts127.0.0......
  • 数据库连接错误:您在wp-config.php文件中提供的数据库用户名和密码可能不正确,或者无法
    为了解决“数据库连接错误”的问题,可以按照以下步骤进行操作:备份现有配置:在修改任何文件之前,请确保备份现有的wp-config.php文件,以防修改出错时能够恢复。重命名配置文件:将根目录下的wp-config-sample.php文件重命名为wp-config.php。这通常可以通过FTP客户端或通过服务器上......
  • 如何解决"Can't connect to MySQL server on 'hostname' (10061)"问题
    当遇到"Can'tconnecttoMySQLserveron'hostname'(10061)"这类错误时,通常意味着应用程序无法连接到MySQL数据库服务器。错误代码10061通常表示连接拒绝,可能是因为服务器没有响应或者不允许来自该客户端的连接。以下是解决此类问题的一些步骤:解决方法:检查数据库服务......
  • 易优eyoucms网站请检查数据库连接信息,Access denied for user 'root'@'localhost' (us
    当你遇到“Accessdeniedforuser'root'@'localhost'(usingpassword:YES)”这样的错误时,这意味着数据库系统拒绝了你的连接请求,通常是由于提供的凭据不正确。你可以按照以下步骤来检查和修改数据库连接信息:检查数据库连接信息:确认数据库用户名(通常是root)、密码、以及数......
  • QEMU on Linux hosts(By frp)
    Invocation—QEMUdocumentationHosts/Linux-QEMU关键字:QEMU、Tips:由于是使用反向代理frp 内网穿透在无图形界面的Ubuntu24.04LTS主机,通过ssh安装QEMU,频繁出现掉线问题,所以使用Screenapt-getinstallscreenroot@atc:~#screen-vScreenversion4.09.01(GNU)20-Au......