参考 https://gist.github.com/fernandoaleman/1376720
如果打不开上一个连接, 请参考 https://www.cnblogs.com/LiuYanYGZ/p/9433756.html
1 如何制作带签名的自定义 rpm 包
操作步骤:
制作 rpm 包的服务器:
由于制作 rpm 包的用户打算使用 rpmuser 用户, 所以可以将 gpg 的一系统操作在 rpmuser 下进行, 我使用的是 root, 然后再将 / root/.gnupg / 拷贝到 / home/rpmuser/.gnugp/ 再改 chown -R rpmuser:rpmuser /home/rpmuser/.gnugp/
- 1)gpg --gen-key
- pg: /root/.gnupg/trustdb.gpg: trustdb created
- gpg: key 2D50D623 marked as ultimately trusted
- public and secret key created and signed.
- 2)gpg --list-keys
- [root@localhost rpmbuild]# gpg --list-keys
- /root/.gnupg/pubring.gpg
- ------------------------
- pub 1024R/2D50D623 2018-08-06
- uid FeiTian (FeiTian Released) <sales@ftsafe.com>
- sub 1024R/FF885B48 2018-08-06
- 3)gpg --export -a 2D50D623> RPM-GPG-KEY
4)配置 ~/.rpmmacros file
- # vim ~/.rpmmacros
- #
- # %_signature => This will always be gpg
- # %_gpg_path => Enter full path to .gnupg in your home directory
- # %_gpg_name => Use the Real Name you used to create your key
- # %_gpbin => run `which gpg` (without ` marks) to get full path
- %_signature gpg
- %_gpg_path /root/.gnupg
- %_gpg_name Fernando Aleman
- %_gpgbin /usr/bin/gpg
5)为 DIY 的包签名
rpm --addsign git-1.7.7.3-1.el6.x86_64.rpm
或
rpm --addsign *.rpm
root 下对未签名的 rpm 包进行签名, 签名后的文件与签名前的相比只是在文件头部 (添加) 修改了一些信息, 签名后大了 344 个字节.
然后 rpmuser 下的操作却整个包没有相同的地方.
6)rpm build 期间可以指定 --sign 来直接得到签名了的 rpm 包
- rpmbuild -ba --sign SPECS/hello.spec
下载 rpm 者:
1)导入发布者公钥 RPM-GPG-KEY
- sudo rpm --import RPM-GPG-KEY
- 2)Verify the list of gpg public keys in RPM DB
- rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n'
3)成功导入公钥后才能验签 (观察'gpg OK')--- 先打包后签名的 rpm 包
[root@localhost GPG]# rpm --checksig /usr/local/hello-0.1-1.x86_64.rpm
/usr/local/hello-0.1-1.x86_64.rpm: rsa sha1 (md5) pgp md5 确定
否则, 提示不正确 --- 先打包后签名的 rpm 包
[root@localhost GPG]# rpm --checksig /usr/local/hello-0.1-1.x86_64.rpm
/usr/local/hello-0.1-1.x86_64.rpm: RSA sha1 (MD5) PGP md5 不正确
注意: 无论是先打包后签名 还是 打包时直接签名, 验签时都显示 "pgp 确定"
[root@localhost GPG]# rpm --checksig ./hello-0.1-1.x86_64.rpm.signed_first_rpm_second_sign
./hello-0.1-1.x86_64.rpm.signed_first_rpm_second_sign: rsa sha1 (md5) pgp md5 确定
- [root@localhost GPG]#
- [root@localhost GPG]#
- [root@localhost GPG]#
- [root@localhost GPG]# rpm --checksig ./hello-0.1-1.x86_64.rpm_rpmbuild_with--sign
./hello-0.1-1.x86_64.rpm_rpmbuild_with--sign: rsa sha1 (md5) pgp md5 确定
来源: http://www.bubuko.com/infodetail-2717458.html