ssh检测公钥和私钥

2019-06-24  本文已影响0人  forjie

1.利用生成的id_rsa生成id_rsa.pub,对比之前的id_rsa.pub文件进行对比

ssh-keygen  -y -f id_rsa > id_rsapub.tobecompared

生成id_rsapub.tobecompared,拿id_rsapub.tobecompared和之前的id_rsa.pub进行对比,如果中间一段是一样的,那么就是相同的

2.利用脚本进行测试,写一个

#!/bin/bash                                                                                                                                                                                   
#set -x                                                                                                                                                                                       
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

执行 sh check_rsa_pub.sh

正确情况下 返回:
************************ id_rsa is OK *************************
next step just enter!
Enter file in which the key is (/home/**/.ssh/id_rsa):
2048 SHA256:WujtUtlk27cdZ+Y8xQBHn4MQmg2je9u5qwme137zwoY panyu@panyu (RSA)
************************ id_rsa.pub is OK *********************

Enter file in which the key is 当运行到这句话的时候回车

上一篇 下一篇

猜你喜欢

热点阅读