如果打不开上一个连接,请参考https://www.cnblogs.com/LiuYanYGZ/p/9433756.html

 

 1 如何制作带签名的自定义rpm包

 

 1 操作步骤:
 2 制作rpm包的服务器:
 3 
 4 由于制作rpm包的用户打算使用rpmuser用户,所以可以将gpg的一系统操作在rpmuser下进行,我使用的是root,然后再将/root/.gnupg/拷贝到/home/rpmuser/.gnugp/ 再改chown -R rpmuser:rpmuser /home/rpmuser/.gnugp/
 5 
 6 1)gpg --gen-key
 7 
 8 pg: /root/.gnupg/trustdb.gpg: trustdb created
 9 gpg: key 2D50D623 marked as ultimately trusted
10 public and secret key created and signed.
11 
12 2)gpg --list-keys
13 [root@localhost rpmbuild]# gpg --list-keys
14 /root/.gnupg/pubring.gpg
15 ------------------------
16 pub   1024R/2D50D623 2018-08-06
17 uid                  FeiTian (FeiTian Released) <sales@ftsafe.com>
18 sub   1024R/FF885B48 2018-08-06
19 
20 
21 3)gpg --export -a 2D50D623 > RPM-GPG-KEY
22 
23 4)配置 ~/.rpmmacros file
24 # vim ~/.rpmmacros
25 #
26 # %_signature => This will always be gpg
27 # %_gpg_path  => Enter full path to .gnupg in your home directory
28 # %_gpg_name  => Use the Real Name you used to create your key
29 # %_gpbin     => run `which gpg` (without ` marks) to get full path 
30 
31 %_signature gpg
32 %_gpg_path /root/.gnupg
33 %_gpg_name Fernando Aleman
34 %_gpgbin /usr/bin/gpg
35 
36 
37 5)为DIY的包签名
38 rpm --addsign git-1.7.7.3-1.el6.x86_64.rpm
39 或
40 rpm --addsign *.rpm
41 root下对未签名的rpm包进行签名,签名后的文件与签名前的相比只是在文件头部(添加)修改了一些信息, 签名后大了344个字节。
42 然后rpmuser下的操作却整个包没有相同的地方。
43 
44 6)rpm build期间可以指定--sign来直接得到签名了的rpm包
45 rpmbuild -ba --sign SPECS/hello.spec
46 
47 
48 
49 
50 
51 
52 下载rpm者:
53 1)导入发布者公钥RPM-GPG-KEY
54 sudo rpm --import RPM-GPG-KEY
55 
56 2)Verify the list of gpg public keys in RPM DB
57 rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n'
58 
59 3)成功导入公钥后才能验签 (观察'gpg OK')---先打包后签名的rpm包
60 [root@localhost GPG]# rpm --checksig /usr/local/hello-0.1-1.x86_64.rpm
61 /usr/local/hello-0.1-1.x86_64.rpm: rsa sha1 (md5) pgp md5 确定
62 否则,提示不正确                        ---先打包后签名的rpm包
63 [root@localhost GPG]# rpm --checksig /usr/local/hello-0.1-1.x86_64.rpm
64 /usr/local/hello-0.1-1.x86_64.rpm: RSA sha1 (MD5) PGP md5 不正确
65 
66 
67 
68 注意:无论是先打包后签名     还是    打包时直接签名,       验签时都显示"pgp 确定"
69 [root@localhost GPG]# rpm --checksig  ./hello-0.1-1.x86_64.rpm.signed_first_rpm_second_sign
70 ./hello-0.1-1.x86_64.rpm.signed_first_rpm_second_sign: rsa sha1 (md5) pgp md5 确定
71 [root@localhost GPG]# 
72 [root@localhost GPG]# 
73 [root@localhost GPG]# 
74 [root@localhost GPG]# rpm --checksig  ./hello-0.1-1.x86_64.rpm_rpmbuild_with--sign 
75 ./hello-0.1-1.x86_64.rpm_rpmbuild_with--sign: rsa sha1 (md5) pgp md5 确定