RHCE进阶必备:一分钟了解HTTPS最重要的过程,ssl/tls协议,ssl握手过程,访问cgi程序,NFS服务器,手动挂载和自动挂载。

目录

1.配置使用ssl完成https访问apache服务器

2.配置访问apache的cgi程序

3.nfs挂载

4.autofs自动挂载

5.使用https来访问的web服务器

6.可选:https中ssl层的握手协议流程


1.配置使用ssl完成https访问apache服务器

mod_ssl是一种以openssl 的工具箱为基础专门为apache webserver 提供密码保护的软件

[root@server conf.d]# systemctl status firewalld

[root@server conf.d]# systemctl stop firewalld
[root@server conf.d]# setenforce 0                            #设置为宽容模式

[root@server ~]# yum install mod_ssl -y

[root@server /]# mkdir /www/myssl

[root@server www]# echo 'this is my first https page.' > ./myssl/index.html
[root@server ~]# cd /etc/httpd/conf.d
[root@server conf.d]# vim myssl.conf                        #额外的配置文件

 [root@server conf.d]# systemctl restart httpd


2.配置访问apache的cgi程序

[root@server conf.d]# cd /var/www/cgi-bin/
[root@server cgi-bin]# vim test.cgi

 [root@server cgi-bin]# chmod +x test.cgi     #其他人没有访问权限,给一个x权限即可


3.nfs挂载


  a、开放/nfs/shared目录,供所有用户查询资料;

  b、开放/nfs/upload目录,该目录为192.168.xxx.0/24网段的主机的数据上传目录,
       并将所有该网段主机上传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;
  c、将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享
       给192.168.xxx.128这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的

       权限。

a:

服务端:

#首先关闭防火墙和SELINUX的状态

RPC主程序:rpcbind

NFS主程序:nfs-utils

[root@server conf.d]# yum install rpcbind nfs-utils -y

[root@server conf.d]# systemctl restart nfs-server.service 
[root@server conf.d]# vim /etc/exports

[root@server ~]# mkdir /nfs/shared -p

[root@server ~]# touch /nfs/shared/file{a..e}

[root@server shared]# exportfs -r       #nfs的特点就是直接挂载,无需重启

 客户端:

[root@server ~]# showmount -e 192.168.30.133  #显示服务端共享文件的位置和信息

[root@server ~]# mount 192.168.30.133:/nfs/shared /mnt  #挂载共享文件到/mnt
[root@server ~]# cd /mnt
[root@server mnt]# ll                                             #查看共享文件的权限
total 0
-rw-r--r--. 1 root root 0 Jul 29 22:24 filea
-rw-r--r--. 1 root root 0 Jul 29 22:24 fileb
-rw-r--r--. 1 root root 0 Jul 29 22:24 filec
-rw-r--r--. 1 root root 0 Jul 29 22:24 filed
-rw-r--r--. 1 root root 0 Jul 29 22:24 filee
[root@server mnt]# touch 1
touch: cannot touch '1': Read-only file system

b:

服务端:

[root@server shared]# vim /etc/exports

 [root@server shared]# mkdir /nfs/upload -p

[root@server nfs]# chmod o+w /nfs/upload/     #修改权限为其他用户可写
[root@server nfs]# ll
total 0
drwxr-xr-x. 2 root root 71 Jul 29 22:24 shared
drwxr-xrwx. 2 root root  6 Jul 29 22:38 upload
[root@server nfs]# touch /nfs/upload/test{a..c}   #给共享目录中添加文件
[root@server nfs]# cd upload/
[root@server upload]# ll
total 0
-rw-r--r--. 1 root root 0 Jul 29 22:41 testa
-rw-r--r--. 1 root root 0 Jul 29 22:41 testb
-rw-r--r--. 1 root root 0 Jul 29 22:41 testc
[root@server upload]# useradd -u 2001 nfs-upload    #添加共享用户和所属组的映射为nfs-                                                                                                           upload,uid和gid都为2001
[root@server upload]# groupmod -g 2001 nfs-upload
[root@server upload]# id nfs-upload                        #查看共享用户和所属组的映射
uid=2001(nfs-upload) gid=2001(nfs-upload) groups=2001(nfs-upload)
[root@server upload]# exportfs -r                               #重启nfs

客户端:

[root@server mnt]# showmount -e 192.168.30.133   #显示服务端的共享文件的位置及信息
Export list for 192.168.30.133:
/nfs/upload 192.168.30.0/24

[root@server mnt]# useradd -u 2001 nfs-upload      #创建和服务端一致的用户及用户组的映                                                                                          射nfs-upload
[root@server mnt]# groupmod -g 2001 nfs-upload


[root@server mnt]# mount 192.168.30.133:/nfs/upload /media/  #挂载
[root@server mnt]# cd /media/
[root@server media]# ll
total 0
-rw-r--r--. 1 root root 0 Jul 29 22:41 testa
-rw-r--r--. 1 root root 0 Jul 29 22:41 testb
-rw-r--r--. 1 root root 0 Jul 29 22:41 testc

c:

服务端:

 [root@server shared]# vim /etc/exports

[root@server upload]# useradd -u 1111 tom
[root@server upload]# id tom
uid=1111(tom) gid=1111(tom) groups=1111(tom)
[root@server upload]# touch /home/tom/tm{a..c}

[root@server upload]# exportfs -r                               #重启

客户端:

[root@server media]# showmount -e 192.168.30.133
Export list for 192.168.30.133:
/nfs/upload 192.168.30.0/24
/home/tom   192.168.30.137
[root@server media]# useradd -u 1111 tom
[root@server media]# id tom
uid=1111(tom) gid=1111(tom) groups=1111(tom)
[root@server media]# mount 192.168.30.133:/home/tom /mnt

4.autofs自动挂载


       远程nfs服务器要的目录为/nfs/autofs
       客户端的的挂载目录/data/autofs
       且设置自动卸载时间为60秒

服务端:

 [root@server upload]# mkdir /nfs/autofs -p
[root@server upload]# chmod o+w /nfs/autofs/
[root@server upload]# vim /etc/exports

客户端:

[root@server media]# yum install autofs -y
[root@server media]# mkdir /data/autofs -p
[root@server media]# vim /etc/auto.master

 [root@server etc]# vim /etc/auto.data

 

 [root@server etc]# vim /etc/auto.data
[root@server etc]# vim /etc/autofs.conf 
[root@server etc]# systemctl restart autofs

 

 我们可以等待1分钟后去查看挂载的状态,正常情况下,1分钟后自动卸载。

5.使用https来访问的web服务器


   要求使用自签名的CA签名证书(openssl, x.509) .crt 以及私钥

5.1. 生成证书

生成私钥

openssl genrsa -des3 -out myCA.key 2048
##openssl genrsa 用于生成RSA私钥,不会生成公钥,因为公钥提取自私钥 
## -des3为加密方式 
## 2048为生成秘钥长度 
## 可以加上-nodes参数,禁止进行加密,即可不运行下面的消除密码

消除私钥key的密码
openssl rsa -in myCA.key -out myCA.key
生成pem文件
openssl req -utf8 -x509 -new -nodes -key myCA.key -sha256 -days 825 -out myCA.pem 

5.2. 创建CA签名证书 

生成私钥
openssl genrsa -out server.key 2048

创建证书签名请求

openssl req -new -key server.key -out server.csr
##Common Name应该与域名保持一致,否则会引起浏览器警告

为扩展创建一个配置文件

>server.ext cat <<-EOF 
authorityKeyIdentifier=keyid,issuer 
basicConstraints=CA:FALSE 
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment 
subjectAltName = @alt_names 
[alt_names] 
DNS.1 = www.baidu.com # Be sure to include the domain name here because Common Name is not so commonly honoured by itself 
DNS.2 = www.sougou.com # Optionally, add additional domains (I've added a subdomain here) 
IP.1 = 192.168.1.1  # Optionally, add an IP address (if the connection which you have planned requires it) EOF 
## chrome 会查看当前域名是否在证书中声明,该声明由 subjectAltName 字段设置。上述的生成步骤默认未设置该字段 

创建签名证书
l x509 -req -in server.csr -CA myCA.pem -CAkey myCA.key -CAcreateserial -out server.crt -days 3650 -sha256 -extfile server.ext 

server.crt
server.key 

6.可选:https中ssl层的握手协议流程

HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer 或 Hypertext Transfer Protocol Secure,超文本传输安全协议),是以安全为目标的HTTP通道。HTTPS并不是一个新协议,而是HTTP+SSL(TLS)。原本HTTP先和TCP(假定传输层是TCP协议)直接通信,而加了SSL后,就变成HTTP先和SSL通信,再由SSL和TCP通信,相当于SSL被嵌在了HTTP和TCP之间。

 SSL 是“Secure Sockets Layer”的缩写,中文叫做“安全套接层”。它是在上世纪90年代中期,由网景公司设计的。到了1999年,SSL 应用广泛,已经成为互联网上的事实标准。IETF 就把SSL 标准化。标准化之后SSL被改为 TLS(Transport Layer Security传输层安全协议)。

SSL协议分为两层:

  • SSL记录协议 (SSL Record Protocol):它建立在可靠的传输协议(如TCP)之上,为高层协议提供数据封装、压缩、加密等基本功能。
  • SSL握手协议(SSL Handshake Protocol):它建立在SSL记录协议之上,用于在实际的数据传输开始前,通讯双方进行身份认证、协商加密算法、交换加密密钥等。

SSL握手协议流程:

第一次握手:

客户端向服务端发送Client Hello报文,该报文中包含了支持的SSL(TLS)版本信息、加密组件(加密算法和秘钥长度等)等。

第二次握手:

服务器向客户端发送三个报文。服务端收到请求后,如果支持SSL通信,会首先以Server Hello报文进行应答,报文内容主要是SSL版本信息和加密组件等。加密组件是从接收到的客户端加密组件中筛选出来的。

然后发送第Certificate报文,包含公钥证书

最后发送ServerHelloDone报文,告知客户端握手协议初始化完成

第三次握手:

客户端发送Client Key Exchange报文给服务器回应。报文中是一串被加密过后的字符串。

然后客户端会发送Change Cipher Spec报文,该报文的作用是提示服务端,接下来的通信都会采用这个随机数加密

最后会发送Finish报文,包含连接至此的整体校验值,握手协议能否成功,是以这个报文为判断标准

第四次握手:

服务器同样发送Change Cipher Spec报文和Finish报文 

 图 源自B站蛋老师

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

shadow_58

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

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

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

打赏作者

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

抵扣说明:

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

余额充值