Linux 系统 OpenSSL 证书生成
一、准备工作
cd /etc/pki/CA
mkdir private crl certs newcerts
echo '01' > serial #在demoCA目录下新建serial文件并写入01。
touch index.txt #在demoCA目录下新建index.txt的空文件
二、CA 根证书
2.1、生成CA根证书私钥
openssl genrsa -out private/cakey.pem 1024 #生成CA认证中心 RSA 私钥
2.2、生成CA根证书
openssl req -new -x509 -key private/cakey.pem -out cacert.pem
特别注意!!
国家、省、组织名一定要填写不能为空,且记住你填写的值
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 (eg, YOUR name) []:(httpd-ssl.conf中的ServerName 名称)
Email Address []:(邮箱)
三、SSL 服务器证书
3.1、生成服务器证书私钥
openssl genrsa -out private/server.key 1024
3.2、生成服务器证书请求文件
利已生成的服务器证书私钥,生成服务器证书请求csr文件
openssl req -new -key private/server.key -out crl/server.csr
1、国家、省要与上面CA证书一致,否则签署时必然要失败。
2、 Common Name 此时相当重要,请输入你需要SSL支持的域名,如 localhost(域名只能一个),否则浏览器提示证书错误。
3.3、签署服务器证书
cd ..
openssl ca -in CA/crl/server.csr -out CA/certs/server.crt
Apache 添加 OpenSSL 支持
一、 加载 Apache SSL 模块
编辑 httpd.conf,分别查找下面2行代码,并去掉前面的#
vim /opt/lampp/etc/httpd.conf
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
cd /opt/lampp/etc/extra
mv httpd-ssl.conf httpd-ssl.conf.bak #备份
vim httpd-ssl.conf #编辑,填入下面内容。
95行
<VirtualHost *:443>
# General setup for the virtual host
DocumentRoot "/opt/lampp/htdocs/test"
ServerName dzbdemo.cdsafe.com.cn
ServerAdmin zhoushengchao@cdsafe.com.cn
ErrorLog "/opt/lampp/logs/error_log"
TransferLog "/opt/lampp/logs/access_log"
......
119行
SSLCertificateFile "/etc/pki/CA/certs/server.crt"
......
130行
SSLCertificateKeyFile "/etc/pki/CA/private/server.key"
更新后重启服务即可
一、准备工作
cd /etc/pki/CA
mkdir private crl certs newcerts
echo '01' > serial #在demoCA目录下新建serial文件并写入01。
touch index.txt #在demoCA目录下新建index.txt的空文件
二、CA 根证书
2.1、生成CA根证书私钥
openssl genrsa -out private/cakey.pem 1024 #生成CA认证中心 RSA 私钥
2.2、生成CA根证书
openssl req -new -x509 -key private/cakey.pem -out cacert.pem
特别注意!!
国家、省、组织名一定要填写不能为空,且记住你填写的值
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 (eg, YOUR name) []:(httpd-ssl.conf中的ServerName 名称)
Email Address []:(邮箱)
三、SSL 服务器证书
3.1、生成服务器证书私钥
openssl genrsa -out private/server.key 1024
3.2、生成服务器证书请求文件
利已生成的服务器证书私钥,生成服务器证书请求csr文件
openssl req -new -key private/server.key -out crl/server.csr
1、国家、省要与上面CA证书一致,否则签署时必然要失败。
2、 Common Name 此时相当重要,请输入你需要SSL支持的域名,如 localhost(域名只能一个),否则浏览器提示证书错误。
3.3、签署服务器证书
cd ..
openssl ca -in CA/crl/server.csr -out CA/certs/server.crt
Apache 添加 OpenSSL 支持
一、 加载 Apache SSL 模块
编辑 httpd.conf,分别查找下面2行代码,并去掉前面的#
vim /opt/lampp/etc/httpd.conf
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
cd /opt/lampp/etc/extra
mv httpd-ssl.conf httpd-ssl.conf.bak #备份
vim httpd-ssl.conf #编辑,填入下面内容。
95行
<VirtualHost *:443>
# General setup for the virtual host
DocumentRoot "/opt/lampp/htdocs/test"
ServerName dzbdemo.cdsafe.com.cn
ServerAdmin zhoushengchao@cdsafe.com.cn
ErrorLog "/opt/lampp/logs/error_log"
TransferLog "/opt/lampp/logs/access_log"
......
119行
SSLCertificateFile "/etc/pki/CA/certs/server.crt"
......
130行
SSLCertificateKeyFile "/etc/pki/CA/private/server.key"
更新后重启服务即可