首先请确认服务器已经安装了openssl,若尚未安装openssl请先安装openssl。
本教程使用openssl提供的一个工具创建服务器私钥和服务器证书以及CA根证书。
cd /var/tmp
wget http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz
tar zxvf ssl.ca-0.1.tar.gz
cd ssl.ca-01
h2. 生成根证书
执行脚本new-root-ca.sh开始生成证书
./new-root-ca.sh
按照服务器提示输入您的信息
Self-sign the root CA...
Enter pass phrase for ca.key:
输入您的新密码
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) [MY]:CN
国家代码
State or Province Name (full name) [Perak]:Beijing
州和省名
Locality Name (eg, city) [Sitiawan]:Beijing
城市名称
Organization Name (eg, company) [My Directory Sdn Bhd]:Beijing CCMSD
公司名称
Organizational Unit Name (eg, section) [Certification Services Division]:
部门名称
Common Name (eg, MD Root CA) []:CCMSD ROOT CA
通用名称
Email Address []:
电子邮件
这样就生成了ca.key和ca.crt两个文件,下面还要为我们的服务器生成一个证书:
h2. 生成服务器私钥和证书
继续执行:
./new-server-cert.sh server
同样回答以上哪些问题。
*注意:这里要特别注意这个Organization Name不能和上面生成CA证书的Organization Name完全一模一样,否则会生成失败!*
h3. 签署证书请求
执行命令:
./sign-server-cert.sh server
证书合并:
cat server.key server.crt > server.pem