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

Can I set SSH known_hosts to ignore a specific hostname?

· 52CE 我爱测

I've set up a few headless Raspberry Pi systems using a Raspbian system image lately. They default to using the zeroconf domain name raspberrypi.local . Before I can change it, I have to connect to the new server with SSH, which …

问题原文

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

I've set up a few headless Raspberry Pi systems using a Raspbian system image lately. They default to using the zeroconf domain name raspberrypi.local. Before I can change it, I have to connect to the new server with SSH, which always barks at me:

> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> @      WARNING: POSSIBLE DNS SPOOFING DETECTED!           @
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

and won't connect until I open the known_hosts file and delete the previous entry. Then when it does connect, it automatically adds a new entry for raspberrypi.local to mess things up next time.

I understand and appreciate the logic of checking the keys and automatically adding new ones, but I think for this specific case it doesn't make sense. I would never be connecting to a server called raspberrypi.local unless it was a new server I just plugged in, and in that case it will never have a known trustworthy key.

I can see from the known_hosts specification that I can set a wildcard on the address side (ie. accept this key from any address in this range) but what I want to do is set a wildcard on the key side (accept any key from this particular domain name). Or better yet, just don't check keys from this domain name at all.

Is there any way to tell known_hosts to ignore (pass without checking keys from) a single specific domain name?

已采纳解答

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

Try this in your ssh_config, this prevents ssh from saving the key, but only for this hostname.

Host raspberrypi.local
  UserKnownHostsFile /dev/null

The manual also mentions StrictHostKeyChecking:

If this flag is set to “no” or “off”, ssh will automatically add new host keys to the user known hosts files and allow connections to hosts with changed hostkeys to proceed, subject to some restrictions.

But I found no details on those restriction, and you don't want to save the hostkey anyway.

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

资料来源与适用范围

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

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

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