linux shell实现生成签名私钥和证书

generate_certificate.sh

#!/bin/bash

#generate private key and certificate
E_DIRECTORY=65

read -p "Please input the directory which store certificate:" directory
if [ ! -d $directory ];then
  echo "$directory does not exist."
  exit $E_DIRECTORY
fi
read -p "Please input key name:" name
openssl genrsa -out ${directory}/${name}.key
openssl req -new -x509 -key ${directory}/${name}.key -subj "/CN=common" -out ${directory}/${name}.crt

验证:

[root@logstash ~]# sh generate_certificate.sh 
Please input the directory which store certificate:/tmp
Please input key name:ztj
Generating RSA private key, 2048 bit long modulus
...........................................................+++
....................................................................+++
e is 65537 (0x10001)
[root@logstash ~]# 
[root@logstash tmp]# cd /tmp
[root@logstash tmp]# cat ztj.key 
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA3g9M7MzlsaPvxSrd5SmN/Nvl0VAQoHdfedc//8h6rthjWRh3
B/XrKOdGQ+YmAPktJMdKehnDXDnAHlzj397r1bh99O8QO6lUATLycBOy+qX6X+vI
kPmpXyG6JcBpO3eEqIIol+Af/l0LJyY3C2eJ6AMtpjTEfO1BZ1T7IRMKuqR7Yqil
i+KAlu49NTaDJ9q5R5Ed/nro1IqY43xXkvUttpYm8NyeZGjq22GswYHX50JiXphU
1bGGko4mSHNTk2iS63RvT7iJ/FEYiAeZi8hIysP8xZMe3WPX2H4PrtlOQ2FvCugM
Vkv8VSKEs9J8EL+E+aoyeCNHLQffNfGr9H2eYQIDAQABAoIBACCpz37lhMPkgVhX
Pdx/iEsxbVSkmk2AQaMCbn+JVcJyQerRFnEtUzHpEwTZza1G+cT3K5VaRMpEFGZi
84HyoG4HfT+SCqk79wdWHyMtQp5r27BQVmg80RUVOPRkoRYGNpUy0BXG+e3IceOI
U4Bx8m8WSJiyGlTl8UDp1ya+Tk21reGinXBtf1J9wB2wZGyffMWGaeJ/BjgrjgcO
dNrqOXNVtiOXXSj4PsfzyeWnY3y4xOM/0R7IGa0oL2u76HjaQ+9VmfX4D1afRwMs
k6a421ZqTQg64NHY48dcaTuR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BAMMBmNvbW1vbjAeFw0yNDA1MzEwMTM3MzdaFw0yNDA2MzAwMTM3MzdaMBExDzAN
BgNVBAMMBmNvbW1vbjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN4P
TOzM5bGj78Uq3eUpjfzb5dFQEKB3X3nXP//Ieq7YY1kYdwf16yjnRkPmJgD5LSTH
SnoZw1w5wB5c49/e69W4ffTvEDupVAEy8nATsvql+l/ryJD5qV8huiXAaTt3hKiC
KJfgH/5dCycmNwtniegDLaY0xHztQWdU+yETCrqke2KopYvigJbuPTU2gyfauUeR
Hf566NSKmON8V5L1LbaWJvDcnmRo6tthrMGB1+dCYl6YVNWxhpKOJkhzU5Nokut0
b0+4ifxRGIgHmYvISMrD/MWTHt1j19h+D67ZTkNhbwroDFZL/FUihLPSfBC/hPmq
MngjRy0H3zXxq/R9nmECAwEAAaNQME4wHQYDVR0OBBYEFGY7hbvcwMAcbyXKlR66
gEfRDVFqMB8GA1UdIwQYMBaAFGY7hbvcwMAcbyXKlR66gEfRDVFqMAwGA1UdEwQF
MAMBAf8wDQYJKoZIhvcNAQELBQADggEBAK30nfJONBNtE+X7CgQb7S3MjoJ7QVQa
o7pwHs94g9tZzQ4kPR2cPmPFmJsI/IvhH07uSnjIfIQoR593UQEAkWFAKCPzMpf4
oitBfgt3llVsnYFxQLeZFJTXlsGc2H0icCoBHuhQZ7HfUA6Sc0KANzZAyL0+x5Rt
jVrABZ+d/aAE1X3jvSf1XKc7N0mGFw9oz6P3U8lSPF+GRPnMR1lDc0fqD7macUKT
iMvmenOX8pCwwQ0i8cmmFj4B2fXZULDpA0hXVcWeMWigtLyY2lW5L9ZZRI4BEsb2
2dn4GQKcxKFlZZriRjx5KUzQ2Fz5DEKkXET+Amq5dr5bwA3ama1OjpE=
-----END CERTIFICATE-----
[root@logstash tmp]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值