为具有相同主机名的不同实验室设置 SSH 配置文件

为具有相同主机名的不同实验室设置 SSH 配置文件

我们有 2 个不同的 AWS 实验室,每个实验室大约有 40 个虚拟机,并且两个实验室的主机名相同。

两个实验室都在一个私有子网中,因此要登录,我们使用名为 bastion 的跳转主机。这是我的实验室 1 的配置文件:

Host bastion001.dev.qwerty.com
    User abc
    IdentityFile xyz.pem

Host <regex for hostname pattern>
    User abc
    IdentityFile xyz.pem
    ProxyCommand ssh -W %h:%p bastion001.dev.qwerty.com

这对于实验室 1 来说工作正常。但是我无法设置另一个配置文件config_2,因为它会给我以下错误:

grimlock$ ssh -F config_2 <hostname of a Lab 2 VM>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:GGnuaKqWJZXFQMaJJxYyUSvUY2FKlCtNxJcyB6+LZDU.
Please contact your system administrator.
Add correct host key in /Users/grimlock/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/grimlock/.ssh/known_hosts:90
ECDSA host key for <hostname of a Lab 2 VM> has changed and you have requested strict checking.
Host key verification failed.

仅供参考,config_2文件包含以下内容:

Host bastion001.qa.qwerty.com
    User abc
    IdentityFile xyz.pem

Host <regex for hostname pattern>
    User abc
    IdentityFile xyz.pem
    ProxyCommand ssh -W %h:%p bastion001.qa.qwerty.com

有人能建议一个解决这个问题的变通方法吗?在实验 2 中每次手动跳过堡垒并不好玩。更改主机名不是一种选择(业务需求)。

编辑:主机名如下所示:xyz-service001xyz-service002。它们不是 FQDN。

答案1

使每个配置使用其自己的known_hosts文件:

Host <...>
    UserKnownHostsFile ~/.ssh/known_hosts.qa

相关内容