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

How to view ECDSA host key of a server?

· 52CE 我爱测

When getting a message like the following, how can I view the key of the server? $ ssh example.com Warning: the ECDSA host key for 'example' differs from the key for the IP address '10.0.0.2' Offending key for IP in /Users/louis/…

问题原文

原帖链接 · Louis Waweru · CC BY-SA 4.0

When getting a message like the following, how can I view the key of the server?

$ ssh example.com
Warning: the ECDSA host key for 'example' differs from the key for the IP address '10.0.0.2'
Offending key for IP in /Users/louis/.ssh/known_hosts:1

When doing ssh -v example.com I can see debug1: Server host key: ecdsa-sha2-nistp256 SHA256:..., but this is not the same as the ssh-rsa key eventually stored in known_hosts after correcting the problem.

已采纳解答

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

One pretty easy way is to use ssh-keyscan. This command will request keys from the remote server. For example if I wanted the rsa, ecdsa, and ed25519 host keys from demo.example.org I might use this command.

$ ssh-keyscan -t rsa,ecdsa,ed25519 demo.example.org

# demo.example.org:22 SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u4
demo.example.org ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBP6LHP2MDkPBtfBF546K9ZlPtJYVF3MMMn0ZMWEY6fkiAR+CPTfPo2l31qHMEJ0g1TT4MM0WBp8/okeBLlkgkhQ=
# demo.example.org:22 SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u4
demo.example.org ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAuVatNRkjLPQOqXF9sVJOgfzKcfVJUlaFv6vfw1sBcxujRnLy0GInn0HxraXxm60dZWlkIyjhzp7CFWK9PNJ/q2NrhPa1NcWLQ4zbandj4whXYXNdysY0LSQzefrXUiEHCIk1lmBuNx59tzAS0I5S6IYH6S72g+g16HNcaJ8SEJnmFpVu5nKzhNVZls47tM+MCVjMZ92xgWkziFgnDqarfxRgL8ZKgnwQ5jPaltNf73qamAuGsMnvR8VfNpeT3QFH2MzYO/um1HYMhiUMKJfL6S4hG0rIFbF4riXnav7XPWpBVRNtLdT2w2z996wxhrvBxNLQAKK2d6jUOHWC+7x7
# demo.example.org:22 SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u4
demo.example.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINEGDaHtAIq+r98FqHL6ERuZ8ZcGyNyu3iW0XOskqQbh

If you wanted the hashed versions and wanted to append them to your known_hosts you could use a command like this.

ssh-keyscan -t rsa,ecdsa,ed25519 -H demo.example.org 2>/dev/null >> .ssh/known_hosts

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

资料来源与适用范围

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

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

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