gpt4 book ai didi

SSH 主机 key 验证仅在其中一个客户端上失败

转载 作者:行者123 更新时间:2023-12-02 14:25:37 27 4
gpt4 key购买 nike

我无法从客户端“A”SSH 到服务器“B”(但我可以从同一子网上的许多其他 ssh 客户端而不是“A”——所有都是 *nux 机器)

serverA>ssh -v -p 端口用户@serverB

OpenSSH_5.3p1 Debian-3ubuntu5, OpenSSL 0.9.8k 25 Mar 2009  
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to serverB [serverB] port PORT.
debug1: Connection established.
debug1: identity file /home/user_A/.ssh/id_rsa type -1
debug1: identity file /home/user_A/.ssh/id_dsa type 2
debug1: Checking blacklist file /usr/share/ssh/blacklist.DSA-1024
debug1: Checking blacklist file /etc/ssh/blacklist.DSA-1024
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5
debug1: match: OpenSSH_5.1p1 Debian-5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu5
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: checking without port identifier
Host key verification failed.

我已经在客户端 A 上检查了以下这些点 - 因为服务器 A 看起来很重要 - :
  • user_A/.ssh 目录权限:700(见 man ssh)
  • user_A/.ssh/known_hosts 权限:644(见 man ssh)
  • user_A/.ssh/known_hosts:不内容 serverB 主机公钥
  • otherusers/.ssh/known_hosts:不包含 serverB 主机公钥

  • 我试过了 :
  • 删除服务器 A 上的 known_hosts:同样的错误仍然存​​在
  • 清空服务器 A 上的 known_hosts:同样的错误
  • 检查主机 key 名称是否与 ssh 服务器配置匹配:ok (HostKey/etc/ssh/ssh_host_rsa_key)
  • 重新生成服务器 B 主机 key (ssh-keygen -t dsa/rsa -f/etc/ssh/ssh_host_dsa/rsa_key):同样的错误
  • serverB 上的 ssh -p PORT me@localhost:它也可以与其他 ssh 客户端
  • 一样工作

    所以我现在真的很累! ssh 专家欢迎回家。

    提前谢谢

    最佳答案

    不明白我对这个特定服务器到底做错了什么..
    仍然“奇怪”的是,在客户端销毁“known_hosts”并没有达到预期的积极效果。

    无论如何,请在以后找到我手动执行的操作,非常丑陋但有效:
    注意:这假设对两台机器(客户端和服务器)具有完全访问权限

    服务器端 :重新生成 2 对 key (rsa 和 dsa)

    ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key  
    ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

    客户端 :
    为用户“foo”生成一对 dsa key (私有(private)和公共(public))
    ssh-keygen -t dsa -f /home/foo/.ssh/my_client_key  

    如果正在运行,则将此新 key 添加到 ssh-agent
    ssh-add /home/foo/.ssh/my_client_key  

    将服务器 ssh_host_rsa_key.pub 的内容添加到客户端/home/foo/.ssh/known_hosts,在 IP/端口之后:
    [server_ip]:server_port copy/paste here the server public rsa key (ctrl+shift+C/V)  
    [server_ip]:server_port copy/paste here the server public dsa key (ctrl+shift+C/V)

    现在回到服务器端 :

    将客户端公钥/home/foo/.ssh/my_client_key.pub 复制/粘贴到/home/bar/.ssh/.authorized_keys 中,以允许连接到用户“foo”以连接到“bar”帐户:

    确保与/etc/ssh/sshd_config 的路径一致,以便能够使用文件 .authorized_keys :
    AuthorizedKeysFile      %h/.ssh/.authorized_keys  

    重新启动 ssh 服务器
    /etc/init.d/ssh restart  

    客户 :现在客户端“foo”可以ssh到服务器上的用户“bar”:
    foo@client>$ ssh -p PORT bar@server_ip  

    注意:在我的情况下,客户端和服务器都在 VM 中本地运行。显然不要将这些设置用于生产。

    编辑 :更仔细地阅读 man ssh 页面,应该可以以非常适当的方式解决这个问题,引用 man:“StrictHostKeyChecking 选项可用于控制主机 key 未知或主机 key 未知的机器的登录变了。”

    关于SSH 主机 key 验证仅在其中一个客户端上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5049119/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com