美文网首页
检验ssh公钥和密钥是否配对

检验ssh公钥和密钥是否配对

作者: AizawaSayo | 来源:发表于2021-04-04 00:05 被阅读0次

    1. 通过私钥生成公钥的值,再自行与当前公钥进行比对

    cd ~/.ssh
    ssh-keygen -y -f id_rsa
    

    在线字符串对比工具

    2. 编写一个sh脚本,运行即可测试

    touch check_rsa.sh
    

    内容如下:

    #!/bin/bash                                                                                                                                                                                   
    #set -x            
    # 切换到.ssh文件夹所在路径                                                                                                                                                                           
    cd /root/.ssh
    #检验私钥是否正确                                                                                                                                         
    openssl rsa -in id_rsa -text -noout &> /dev/null                                                                                                         
    if [ $? -ne 0 ]; then                                                                                                                                    
      echo "************************ id_rsa error *************************"                                                                                                                      
    else                                                                                                                                                     
      echo "************************ id_rsa is OK *************************"                                                                                                                      
    fi                                                                                                                                                       
    echo "next step: just enter!"   
    #检验公钥是否正确                                                                                                                                                                                           
    ssh-keygen -l                                                                                                                                            
    if [ $? -ne 0 ]; then                                                                                                                                    
      echo "************************ id_rsa.pub error *********************"                                                                                                                      
    else                                                                                                                                                     
      echo "************************ id_rsa.pub is OK *********************"                                                                                                                      
    fi
    

    切换到check_rsa.sh所在目录,运行它:
    sh check_rsa.sh
    看看有没有输出error。

    相关文章

      网友评论

          本文标题:检验ssh公钥和密钥是否配对

          本文链接:https://www.haomeiwen.com/subject/hmjkkltx.html