zoukankan      html  css  js  c++  java
  • 验证远程主机SSH指纹

    远程主机指纹的作用:用于验证远程主机确实是我以前连接过的主机,而不是被DNS劫持的主机。

    远程主机:ubuntu20.04系统

    本地:wsl 2 的debian 10系统

    所谓的主机指纹:把远程主机的公钥用一种hash算法输出一个较短的数串。

    这就涉及到2个材料:1、远程主机的公钥。2、双方公用的哈希函数。

    本文远程主机公钥是:椭圆算法生成的公钥,名称是:ssh_host_ecdsa_key.pub

    哈希函数是:sha256

    开始验证:

    1、现在远程主机运行: ssh-keygen -E sha256 -lf ssh_host_ecdsa_key.pub 

    生成远程主机的指纹:

    256 SHA256:1G4x9S7Ymt2QrAu0mohEmvwbV8tGBGqBlGtX+Nac2uI root@remotehost (ECDSA)

    查看ssh-keygen --help 得知:  ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile] 

     -l      Show fingerprint of specified public key file. 
     -f filename  Specifies the filename of the key file.
     -E fingerprint_hash  Specifies the hash algorithm used when displaying key fingerprints.  Valid options are: “md5” and “sha256”.  The default is “sha256”.

    2、使用ssh-keyscan扫描远程主机,获取公钥,并用相同的哈希函数计算一下:

    ssh-keyscan.exe -t ECDSA -p 22 12.12.12.12(远程ip) | ssh-keygen.exe -E sha256 -lf -

    输出:

    # 12.12.12.12:22 SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
    256 SHA256:1G4x9S7Ymt2QrAu0mohEmvwbV8tGBGqBlGtX+Nac2uI 12.12.12.12 (ECDSA)

    3、可以看到 1 和 2 生成的指纹是相同的。

  • 相关阅读:
    Spring Boot 配置元数据指南
    面试中常被提到的最左前缀匹配原则
    MyBatis缓存机制(一级缓存,二级缓存)
    计算机网络基础知识
    垃圾收集算法与垃圾收集器
    递归与分治策略
    五种IO模型和BIO,NIO,AIO
    七种阻塞队列
    ConcurrentHashMap(1.7版本和1.8版本)
    重入锁 ReentrantLock
  • 原文地址:https://www.cnblogs.com/litifeng/p/14770756.html
Copyright © 2011-2022 走看看