如何响应bash中的提示

时间:2013-12-28 09:43:38

标签: bash openssl

我需要生成很多私钥和自签名证书,所以我想制作一个bash脚本来为我做。我遇到的问题是,当您自我签署证书时,它会询问与您生成签名请求相同的问题。

即:

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:  
State or Province Name (full name) [Some-State]: 
Locality Name (eg, city) []: 
Organization Name (eg, company) [Internet Widgits Pty Ltd]: 
Organizational Unit Name (eg, section) []: 
Common Name (e.g. server FQDN or YOUR name) []: 
Email Address []: 

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

我已经尝试了几个我在网站上看到的东西,但它们似乎都没有用。这可能是因为我对bash很新。

我的脚本目前看起来像这样:

#!/bin/bash

openssl genrsa -out privkey.pem 2048

openssl req -new -key privkey.pem -out cert.csr

我尝试使用一个管道来回显我想要输入的内容,但它不起作用。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

请参阅以下提供的示例:

http://www.openssl.org/docs/apps/req.html#EXAMPLES

或者在命令行中执行所有操作:

openssl req -new -newkey rsa:4096 -days 365 -nodes -x509\ 
 -subj "/C=US/ST=Denial /L=Springfield/O=Dis/CN=www.example.com" \
 -keyout www.example.com.key  -out www.example.com.cert
相关问题