gpg签名批量验证的2个脚本
gpq签名验证
gpg --import some_pub-key.txt 导入公钥
gpg --fingerprint 打印指纹
gpg --edit-key "some key is uid" trust 设置信任级别
gpg --verify file-name.asc 验证签名。
根据asc验证文件的批量验证脚本,只检查当前目录
[root@FTPServer1 software]# cat gpg.sh
#!/bin/bash
ls *.asc | awk '{ print "gpg --verify ",$1 }' > gpgall.sh
if [ $? -ne 0 ]; then
echo "Can't write file!"
exit 1
fi
sh ./gpgall.sh > gpgall.log 2>&1
echo "gpg verify is done. Please check gpgall.log, and make sure every file is Good signature!"
num_asc=`ls *.asc| wc -l`
num_good_sign=`grep "Good signature" gpgall.log | wc -l`
echo "Total asc file is: ${num_asc}."
echo "Total Good signature is: ${num_good_sign}."
echo -n "You can press y to check the File: "
read result
if [ $result == "y" ]; then
cat gpgall.log
fi
rm ./gpgall.sh
文件多时,等待时间长,且要全部结束时才提示。
第二版,逐个文件提示
[root@FTPServer1 software]# cat gpg.sh
#!/bin/bash
log_file=gpgall.log
# clear file
[ -f ${log_file} ] && rm ${log_file}
[ -f tmp_file ] && rm tmp_file
echo "Begin verify asc......"
num=1
for asc_file in `ls *.asc`
do
echo -e "\n${num}.\t${asc_file}"
echo -e "\n${num}.\t${asc_file}" >>${log_file}
gpg --verify ${asc_file} > tmp_file 2>tmp_file
good_sign=`grep "Good signature" tmp_file | wc -l`
cat tmp_file>>${log_file}
if [ $good_sign == "1" ] ; then
echo "Good signature!"
else
echo "Error! Bad signature!"
fi
((num++))
done
echo -e "\nverify asc is done. "
echo "Please check ${log_file}, and make sure every file is Good signature!"
num_asc=`ls *.asc| wc -l`
num_good_sign=`grep "Good signature" ${log_file} | wc -l`
echo -e "\nTotal asc file is: ${num_asc}."
echo -e "Total Good signature is: ${num_good_sign}.\n"
echo -n "You can press y to check the File: "
read result
[ $result == "y" -o $result == "Y" ] && cat ${log_file}
rm ./tmp_file
abc目录有3个zip文件未下载,只下载了asc文件,可以正确识别
[root@FTPServer1 abc]# ./gpg.sh
Total asc file is: 39.
Total Good signature is: 36.
You can press y to check the File: n