PKI(Public Key Infrastructure)公钥基础设施是提供公钥加密和数字签名服务的系统或平台,目的是为了管理密钥和证书。一个机构通过采用PKI 框架管理密钥和证书可以建立一个安全的网络环境
PKI 主要包括四个部分:X.509 格式的证书(X.509 V3)和证书废止列表CRL(X.509 V2);CA 操作协议;CA管理协议;CA政策制定
X.509通用的证书格式包含三个文件:key,csr,crt。
key是私钥文件
csr是证书签名请求文件,用于提交给证书颁发机构(CA)对证书签名
crt是由证书颁发机构(CA)签名后的证书,或者是开发者自签名的证书,包含证书持有人的信息,持有人的公钥,以及签署者的签名等信息
[root@server ~]# yum install mod_ssl -y
[root@server ~]# vim /etc/httpd/conf.d/ssl.conf # 打开主配置文件
# 常用参数如下:
5 Listen 443 https # 监听的端口号
18 SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog # 存储证书的密码信息
23 SSLSessionCache shmcb:/run/httpd/sslcache(512000) # ssl的缓存,位置
24 SSLSessionCacheTimeout 300 # 换存的超时时长
40 <VirtualHost _default_:443> # 重要,定义虚拟主机的信息
48 ErrorLog logs/ssl_error_log # 错误日志
49 TransferLog logs/ssl_access_log # 传输日志
50 LogLevel warn # 日志等级
54 SSLEngine on # ssl引擎开启
66 SSLHonorCipherOrder on # 协商算法
85 SSLCertificateFile /etc/pki/tls/certs/localhost.crt # 证书存储路径
93 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key # 私钥文件路径
202 </VirtualHost> # 虚拟主机结束定义
# 恢复快照
[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# yum install httpd mod_ssl -y
[root@server ~]# systemctl start httpd # 启动httpd
[root@server ~]# systemctl enable httpd # 设置开机启动
[root@server ~]# mkdir -p /www/zy
# 私用xftp将windows的zy网站数据文件上传到/www/zy目录中
[root@server ~]# cd /etc/pki/tls/private # 进入私钥文件存储目录
[root@server private]# openssl genrsa -aes128 2048 > zy.key # 建立私钥文件
Enter PEM pass phrase: # 密码123456
Verifying - Enter PEM pass phrase: # 再输一遍密码123456
[root@server private]# cd /etc/pki/tls/certs
[root@server certs]# openssl req -utf8 -new -key /etc/pki/tls/private/zy.key -x509 -days 365 -out zy.crt
Enter pass phrase for /etc/pki/tls/private/zy.key: # 输入私钥加密密码123456
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) [XX]:86 # 国家代码
State or Province Name (full name) []:shanxi # 省份
Locality Name (eg, city) [Default City]:xi'an # 城市
Organization Name (eg, company) [Default Company Ltd]:openlab # 公司
Organizational Unit Name (eg, section) []:RHCE # 部门
Common Name (eg, your name or your server's hostname) []:server # 主机名
Email Address []:[email protected] # 邮箱
# 输入内容时,若输入错误,使用ctrl+退格 进行删除
[root@server certs]# cd ~
[root@server ~]# vim /etc/httpd/conf.d/ssl.conf
# 定位第一行,输入以内内容
<virtualhost 192.168.13.134:443>
sslengine on
SSLCertificateFile /etc/pki/tls/certs/zy.crt
SSLCertificateKeyFile /etc/pki/tls/private/zy.key
servername 192.168.13.134
documentroot /www/zy
</virtualhost>
<directory /www/zy>
allowoverride none
require all granted
</directory>
[root@server certs]# cd ~
[root@server ~]# vim /etc/httpd/conf.d/ssl.conf
[root@server ~]# systemctl restart httpd
Enter TLS private key passphrase for 192.168.13.134:443 (RSA) : ****** # 需要输入私钥的密码123456
# 在windows端打开浏览器,输入https://192.168.13.134,点击高级->接受风险并继续
# 恢复快照
[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# yum install httpd mod_ssl -y
[root@server ~]# systemctl start httpd # 启动httpd
[root@server ~]# systemctl enable httpd # 设置开机启动
[root@server ~]# mkdir -p /www/file
[root@server ~]# mkdir -p /www/ftp
[root@server ~]# echo "file" > /www/file/index.html # 写入网站数据
[root@server ~]# echo "ftp" > /www/ftp/index.html
[root@server ~]# vim /etc/hosts # 添加如下内容
192.168.48.130 www.openlab.com
[root@server ~]# vim /etc/httpd/conf/httpd.conf
<virtualhost 192.168.48.130>
documentroot /www/file
alias /file /www/file
servername 'file'
</virtualhost>
<directory /www/file>
allowoverride none
require all granted
</directory>
[root@server ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/ftp.key # 设置私钥文件
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
[root@server ~]# openssl req -utf8 -new -key /etc/pki/tls/private/ftp.key -x509 -days 365 -out /etc/pki/tls/certs/ftp.crt # 设置证书
Enter pass phrase for /etc/pki/tls/private/ftp.key: # 输入私钥密码123456
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) [XX]:86
State or Province Name (full name) []:shanxi
Locality Name (eg, city) [Default City]:xi'an
Organization Name (eg, company) [Default Company Ltd]:openlab
Organizational Unit Name (eg, section) []:RHCE
Common Name (eg, your name or your server's hostname) []:server
Email Address []:[email protected]
[root@server ~]# vim /etc/httpd/conf.d/ssl.conf
# 定位第一行,输入以下内容:
<virtualhost 192.168.48.130:443>
sslengine on
SSLCertificateFile /etc/pki/tls/certs/ftp.crt
SSLCertificateKeyFile /etc/pki/tls/private/ftp.key
servername 'ftp'
documentroot /www/ftp
alias /ftp /www/ftp # 设置别名访问二级目录
</virtualhost>
<directory /www/ftp>
allowoverride none
require all granted
</directory>
[root@server ~]# systemctl restart httpd
Enter TLS private key passphrase for ftp:443 (RSA) : ****** # 输入私钥的密码123456
# 虚拟机中打开火狐浏览器,输入www.openlab.com/file
# 虚拟机中打开火狐浏览器,输入https://www.openlab.com/ftp,点击高级->接受风险并继续