大网数据广告活动
服务器运维问答

How so I SSH to two different machines with the same IP?

· 52CE 我爱测

I have two similar deployments of a web app, each on separate virtual network with private IP addresses. Both have a VM at 10.0.4.4. I can VPN from my development machine into either network and SSH onto the VMs however when I sw…

问题原文

原帖链接 · Brendan · CC BY-SA 4.0

I have two similar deployments of a web app, each on separate virtual network with private IP addresses. Both have a VM at 10.0.4.4.

I can VPN from my development machine into either network and SSH onto the VMs however when I switch networks SSH kicks up a fuss about the hosts having different keys.

Can I configure multiple key signatures against a single hostname to avoid this? What is the recommended way to connect to different machines which have the same IP?

已采纳解答

原帖链接 · A.B · CC BY-SA 4.0

SSH checks its known_hosts for all entries for this host. If all of them don't match, including the usual case of all being the single one entry, then SSH will complain.

If any of them matches SSH succeeds at host checking.

From man sshd in SSH_KNOWN_HOSTS FILE FORMAT:

When performing host authentication, authentication is accepted if any matching line has the proper key; either one that matches exactly or, if the server has presented a certificate for authentication, the key of the certification authority that signed the certificate.

[...]

It is permissible (but not recommended) to have several lines or different host keys for the same names. This will inevitably happen when short forms of host names from different domains are put in the file. It is possible that the files contain conflicting information; authentication is accepted if valid information can be found from either file.

One (less un)common usage of this is for SSH servers often used as SFTP servers in high-availability context through a VIP: when there's a failover from one node to the other, the host authentication can change.

One can use ssh-keyscan 10.0.4.4 possibly with additional options (such as option -H for hashing privacy) twice: once on each different VM, to retrieve all possible host keys and append them or some of them to ~/.ssh/known_hosts.

Then no authentication error will happen anymore, until trying to access a 3rd unrelated node with the same address.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-09-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。