• Linux--CE-->HTTPS,CGI,NFS,AUTOFS,握手协议


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

    (1)首先需要进行安装mod_ssl,(mod_ssl是一种以openssl工具箱为基础的专门为qpache webserver提供密码保护的软件)

    [root@rhce-128 ~]# yum install -y mod_ssl

    # 创建一个目录,ssl要访问的目录,index.html

    1. [root@rhce-128 conf.d]# cd /www/
    2. [root@rhce-128 www]# ls
    3. ip port
    4. [root@rhce-128 www]# mkdir myssl
    5. [root@rhce-128 www]# cd myssl/
    6. [root@rhce-128 myssl]# echo this is my first https page > index.html
    7. [root@rhce-128 myssl]# ls
    8. index.html
    9. [root@rhce-128 myssl]# cat index.html
    10. this is my first https page
    11. [root@rhce-128 myssl]#

    # 设置目录的权限;

    1. <Directory "/www/myssl">
    2. AllowOverride None
    3. Require all granted
    4. Directory>

    # 设置虚拟主机;需要用到Ip,最好自己进行设置;

    1. <Directory "/www/myssl">
    2. AllowOverride None
    3. Require all granted
    4. Directory>
    5. #Listen 443
    6. 192.168.188.140:443>
    7. SSLEngine on
    8. SSLProtocol all -SSLv2 -SSLv3
    9. SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA
    10. SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    11. SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    12. DocumentRoot "/www/myssl"
    13. ServerName 192.168.188.128

    #:配置好文件后,将服务进行重启:

    [root@rhce-128 private]# systemctl restart httpd

    #//:这里有个最最最重要的问题就是,Linux的版本问题,如果你是Centos8以下的版本,你再配置是一定要按照自己的ssl.conf文件中的要求进行配置;

    我的是CentOS7b版本:

    1. SSLProtocol all -SSLv2 -SSLv3
    2. # SSL Cipher Suite:
    3. # List the ciphers that the client is permitted to negotiate.
    4. # See the mod_ssl documentation for a complete list.
    5. SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA

    # :进行完一系列的配置之后,去浏览器访问,结果如下:

    2.配置访问apache的cgi程序

    (1):首先进入到 /var/www/cgi-bin 创建一个test.cgi文件写入一下内容;

    1. [root@rhcsa cgi-bin]# cat test.cgi
    2. #!/bin/bash
    3. printf "Content-Type: text/html;charset=utf-8\n\n";
    4. printf "Hello, World.";
    5. [root@rhcsa cgi-bin]#

    (2):修改test.cgi 文件的权限,因为Linux中的文件在浏览器中去访问,浏览器被当做其他用户,所以必须添加访问权限才可以正常去访问;先来看一下初始的权限和访问结果:

    1. [root@rhcsa cgi-bin]# ll
    2. total 4
    3. -rw-r--r--. 1 root root 88 Jul 30 21:56 test.cgi

    访问结果:

    修改文件的权限:

    1. [root@rhcsa cgi-bin]# chmod 755 test.cgi
    2. [root@rhcsa cgi-bin]# ll
    3. total 4
    4. -rwxr-xr-x. 1 root root 88 Jul 30 21:56 test.cgi
    5. [root@rhcsa cgi-bin]#

     访问结果如下:

    3.nfs挂载

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

    (1):首先安装 rpcbind和nfs-utils这两个软件:

    [root@rhce-128 ~]# yum install rpcbind nfs-utils -y

    (2):创建、/nfs/shared目录,并且在nfs主配置文件中进行配置,

    1. [root@rhce-128 conf]# mkdir -p /nfs/shared
    2. [root@rhce-128 ~]# cd /nfs/shared
    3. [root@rhce-128 shared]# touch file{1..3}
    4. [root@rhce-128 shared]# echo 111 > file1
    5. [root@rhce-128 shared]# echo 222 > file2
    6. [root@rhce-128 shared]# echo 333 > file3
    7. [root@rhce-128 shared]# ll
    8. total 12
    9. -rw-r--r--. 1 root root 4 Jul 31 21:06 file1
    10. -rw-r--r--. 1 root root 4 Jul 31 21:07 file2
    11. -rw-r--r--. 1 root root 4 Jul 31 21:07 file3
    12. [root@rhce-128 shared]# cat file1
    13. 111
    14. [root@rhce-128 shared]# cat file2
    15. 222
    16. [root@rhce-128 shared]# cat file3
    17. 333
    18. [root@rhce-128 shared]#
    19. [root@rhce-128 ~]# cat /etc/exports
    20. /nfs/shared *(ro)

    (3):启用服务,一定要先启用rpcbind,再启用nfs服务,

    1. [root@rhce-128 shared]# systemctl restart rpcbind
    2. [root@rhce-128 shared]# systemctl restart nfs
    3. [root@rhcsa data]# systemctl restart nfs-server
    4. [root@rhce-128 shared]#

    (4):启动另一台虚拟机作为客户机,访问我们这台服务器主机:

    #:首先查看是否可以查询到服务器的共享目录:

    1. [root@rhcsa ~]# showmount -e 192.168.188.128
    2. Export list for 192.168.188.128:
    3. /nfs/shared *
    4. [root@rhcsa ~]#

    (5):挂载服务器的目录到本机,注意服务器上的目录权限,不可为只读,设置744权限的话,挂载完成之后无法进入目录,提示权限不够,所以这里服务器的目录设置为755即可,因为在设置、nfs/exports主配置时,设置的是ro权限,所以值能查看文件,不能修改

    1. [root@rhcsa ~]# mkdir /data
    2. [root@rhcsa ~]# mount 192.168.188.128:/nfs/shared /data/
    3. [root@rhcsa ~]# cd /data/
    4. [root@rhcsa data]# ll
    5. total 12
    6. -rw-r--r--. 1 root root 4 Jul 31 2022 file1
    7. -rw-r--r--. 1 root root 4 Jul 31 2022 file2
    8. -rw-r--r--. 1 root root 4 Jul 31 2022 file3
    9. [root@rhcsa data]# cat file1
    10. 111
    11. [root@rhcsa data]#

    #:做到这里就实现了开放/nfs/shared目录,供所有用户查询资料

    #:若要对目录的资源进行更新,则可以使用 exportfs -a 

            b、开放/nfs/upload目录,该目录为192.168.xxx.0/24网段的主机的数据上传目录,并将所有该网段主机上传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;

    (1):创建共享目录,并修改文件权限:

    1. [root@rhce-128 nfs]# mkdir upload
    2. [root@rhce-128 nfs]# ll
    3. total 0
    4. drwxrwxrwx. 2 root root 45 Jul 31 22:07 shared
    5. drwxr-xr-x. 2 root root 6 Jul 31 22:36 upload
    6. [root@rhce-128 nfs]# chmod 755 upload/
    7. [root@rhce-128 nfs]# ll
    8. total 0
    9. drwxrwxrwx. 2 root root 45 Jul 31 22:07 shared
    10. drwxr-xr-x. 2 root root 6 Jul 31 22:36 upload
    11. [root@rhce-128 nfs]#

    (2):配置主文件,创建用户且指定UID,GID并重新加载资源:

    1. [root@rhce-128 /]# cat /etc/exports
    2. /nfs/upload 192.168.188.0/24(rw,anonuid=2001,anongid=2001)
    3. [root@rhce-128 upload]# useradd -u 2001 nfs-upload
    4. [root@rhce-128 upload]# tail -1 /etc/passwd
    5. nfs-upload:x:2001:2001::/home/nfs-upload:/bin/bash
    6. [root@rhce-128 /]# exportfs -r
    7. [root@rhce-128 /]#

    (3):在客户机进行挂载并测试,先给服务器目录操作权限:

    1. [root@rhce-128 nfs]# chmod 777 upload/
    2. [root@rhce-128 nfs]# exportfs -a

    # :客户端测试:

    1. [root@rhcsa ~]# showmount -e 192.168.188.128
    2. Export list for 192.168.188.128:
    3. /nfs/upload 192.168.188.0/24
    4. [root@rhcsa ~]# mount 192.168.188.128:/nfs/upload /data/
    5. [root@rhcsa ~]# cd /data/
    6. [root@rhcsa data]# ls
    7. file1
    8. [root@rhcsa data]# ll
    9. total 4
    10. -rw-r--r--. 1 root root 13 Aug 1 09:17 file1
    11. [root@rhcsa data]# echo this is file2 > file2
    12. [root@rhcsa data]# ll
    13. total 8
    14. -rw-r--r--. 1 root root 13 Aug 1 09:17 file1
    15. -rw-r--r--. 1 2001 2001 14 Aug 1 09:20 file2
    16. [root@rhcsa data]#

    #:服务器结果显示:

    1. [root@rhce-128 nfs]# ll upload/
    2. total 8
    3. -rw-r--r--. 1 root root 13 Aug 1 09:17 file1
    4. -rw-r--r--. 1 nfs-upload nfs-upload 14 Aug 1 09:20 file2
    5. [root@rhce-128 nfs]#

            c、将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享192.168.xxx.130这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。

    (1):在服务端上创建用户tom,且用户UID和GID分别为1111,在客户端创建用户jerry,

    # 服务端:

    1. [root@rhce-128 home]# useradd -u 1111 tom
    2. [root@rhce-128 home]# ll
    3. total 0
    4. drwx------. 2 tom tom 62 Aug 1 09:30 tom
    5. [root@rhce-128 home]# tail -1 /etc/passwd
    6. tom:x:1111:1111::/home/tom:/bin/bash
    7. [root@rhce-128 home]# chmod 777 tom/
    8. [root@rhce-128 home]# ll
    9. total 0
    10. drwx------. 2 nfs-upload nfs-upload 62 Aug 1 09:15 nfs-upload
    11. drwxrwxrwx. 2 tom tom 74 Aug 1 09:37 tom
    12. [root@rhce-128 home]# exportfs -a

    # 客户端:

    1. [root@rhcsa data]# useradd jerry
    2. [root@rhcsa data]# tail -1 /etc/passwd
    3. jerry:x:1008:1012::/home/jerry:/bin/bash
    4. [root@rhcsa data]# showmount -e 192.168.188.128
    5. Export list for 192.168.188.128:
    6. /home/tom 192.168.188.130
    7. [root@rhcsa /]# cd /data/
    8. [root@rhcsa data]# ll
    9. total 0
    10. -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe
    11. [root@rhcsa data]# su - jerry
    12. [jerry@rhcsa ~]$ cd /data/
    13. [jerry@rhcsa data]$ ll
    14. total 0
    15. -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe
    16. [jerry@rhcsa data]$ touch haha
    17. [jerry@rhcsa data]$ ll
    18. total 0
    19. -rw-rw-r--. 1 jerry jerry 0 Aug 1 09:41 haha
    20. -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe
    21. [jerry@rhcsa data]$ rm -rf haha
    22. [jerry@rhcsa data]$ ll
    23. total 0
    24. -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe
    25. [jerry@rhcsa data]$ echo hehe > hehe
    26. -bash: hehe: Permission denied
    27. [jerry@rhcsa data]$

    4.autofs自动挂载

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

    (1):创建服务器端的目录 /nfs/autofs ,客户端挂载目录为:/data/autofs

    #:服务端:指定autofs目录的权限,并创建挂载目录在主配置文件中:

    1. [root@rhce-128 nfs]# mkdir autofs
    2. [root@rhce-128 nfs]# chmod o+w /nfs/autofs/
    3. [root@rhce-128 nfs]# ll
    4. total 0
    5. drwxr-xrwx. 2 root root 6 Aug 1 09:46 autofs
    6. drwxrwxrwx. 2 root root 45 Jul 31 22:07 shared
    7. drwxrwxrwx. 2 root root 32 Aug 1 09:20 upload
    8. [root@rhce-128 nfs]# vim /etc/exports
    9. [root@rhce-128 nfs]# exportfs -a
    10. [root@rhce-128 nfs]# cat /etc/exports
    11. /home/tom 192.168.188.130(rw)
    12. /nfs/autofs *(rw)
    13. [root@rhce-128 nfs]#

    #客户端:挂载是在客户端上进行的,会持续检测目录,访问时,自动挂载,所以需要先在客户端安装软件autofs,然后再到 /etc/auto.master文件中进行配置,

    1. [root@rhcsa /]# mkdir /data/autofs
    2. [root@rhcsa data]# yum install -y autofs.x86_64
    3. [root@rhcsa data]# vim /etc/auto.master
    4. -------------------------
    5. #
    6. /data /etc/autofs
    7. /misc /etc/auto.misc
    8. #
    9. -------------------------
    10. [root@rhcsa data]# vim /etc/auto.data // 配置挂载目录中的挂载对象;
    11. [root@rhcsa data]# cat /etc/auto.data
    12. autofs -fstype=nfs,rw 192.168.188.128:/nfs/autofs
    13. [root@rhcsa data]#

    #:超时时间设置:下面可以看到等待时间太长,所以我们可以调整一下超时时间;

    1. ---------------
    2. #
    3. timeout = 300
    4. #
    5. -------------- // 这里的单位是秒
    6. #
    7. timeout = 60
    8. #
    9. --------------

    #重启服务:验证结果:

    1. [root@rhcsa data]# systemctl restart autofs
    2. [root@rhcsa data]# ll
    3. total 0
    4. drwxr-xr-x. 2 nfsnobody nfsnobody 6 Aug 1 09:48 autofs
    5. -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe
    6. [root@rhcsa data]#

    # :可以看到文件以及自动挂载成功:

    5 .使用https来访问的web服务器:要求使用自签名的CA签名证书(openssl, x.509) .crt以及私钥

    (1):首先前提是可以正常使用https协议访问,然后生成RSA私钥以及自签名证书:

    1. [root@rhce-128 ~]# openssl req -newkey rsa:2048 -nodes -keyout rsa_private.key -x509 -days 36500 -out cert.crt
    2. Generating a 2048 bit RSA private key
    3. .................+++
    4. ..........................+++
    5. writing new private key to 'rsa_private.key'
    6. -----
    7. You are about to be asked to enter information that will be incorporated
    8. into your certificate request.
    9. What you are about to enter is what is called a Distinguished Name or a DN.
    10. There are quite a few fields but you can leave some blank
    11. For some fields there will be a default value,
    12. If you enter '.', the field will be left blank.
    13. -----
    14. Country Name (2 letter code) [XX]:cn
    15. State or Province Name (full name) []:shanxi
    16. Locality Name (eg, city) [Default City]:xian
    17. Organization Name (eg, company) [Default Company Ltd]:
    18. Organizational Unit Name (eg, section) []:
    19. Common Name (eg, your name or your server's hostname) []:128
    20. Email Address []:

    #:默认放到了root目录下:

    1. [root@rhce-128 ~]# ll /root
    2. total 24
    3. -rwxr-xr-x. 1 root root 110 Aug 1 10:48 1.sh
    4. -rw-------. 1 root root 1736 Jun 3 10:05 anaconda-ks.cfg
    5. -rw-r--r--. 1 root root 1285 Aug 1 12:08 cert.crt
    6. -rw-r--r--. 1 root root 1708 Aug 1 12:08 rsa_private.key
    7. drwxr-xr-x. 3 root root 68 Jun 3 15:33 test
    8. -rw-r--r--. 1 root root 37 Aug 1 10:53 tt
    9. -rw-r--r--. 1 root root 33 Jun 3 15:53 ttssb.txt
    10. [root@rhce-128 ~]#

    #:现在去使用自签名证书,使用https协议访问服务器,先修改配置文件中的证书以及私钥

    配置完成之后重启服务:

    1. 192.168.188.140:443>
    2. SSLEngine on
    3. SSLProtocol all -SSLv2 -SSLv3
    4. SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA
    5. SSLCertificateFile /root/cert.crt
    6. SSLCertificateKeyFile /root/rsa_private.key
    7. DocumentRoot "/www/myssl"
    8. #ServerName 192.168.188.128
    9. Alias "/data" "/www/virtualDir/test.html"
    10. ScriptAlias "/bin" "/www/mybin"
    11. [root@rhce-128 conf.d]# systemctl restart httpd

    # :执行结果:可以看到使用自签名证书也是可以访问页面的:

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

    握手协议流程:(四个阶段)

    第一次阶段:

            客户端发送ClientHello给服务器,服务器处理请求后返回ServerHello包,在这个阶段,不会发送CA证书,本阶段进行的任务是协商版本,协商加密套件,产生随机数等;

    第二个阶段:

            服务器想客户端返回certificate(CA证书),如果是第一次访问,那么必须发送证书证明身份,若服务器想客户端发送Certificate Request包,那么客户端就必须要想服务器发送自己的CA证书;

    第三个阶段:

            秘钥交换阶段,Server Key Exchange,这个阶段不会发送秘钥,客户端和服务器通过在第一阶段产生的随机数Server_random,Client_random,计算得出premaster(第三个随机数),通过这三个随机数产生主密钥,也就是会话秘钥(具有随机性,时效性),客户端将自己产生的会话秘钥通过服务器的公钥打包发送给服务器,服务器,通过自己的秘钥解密,通过相同的算法得到客户端的会话秘钥,和自己计算得出的会话秘钥进行比较,若是相同的,则可以确定身份,后面的通信通过回话秘钥加密即可,提高效率;

    第四个阶段:确认阶段;

            确认双方身份,返回确认信息,开始通信;

  • 相关阅读:
    力扣--76. 最小覆盖子串
    Confluence 内容管理
    【MySQL】MySQL 官方安装包形式
    4个实用小工具安利,你不看看吗
    What I Read(1) 地理空间数据库原理(A) 绪论
    带你玩转序列模型之NLP与词嵌入(一)
    oauth2单点登录集成
    C# 随机给一个全部信息都未知的类类型,如何获取该类的类名、属性个数、属性名、属性的数据类型、属性值?
    vulnhub之raven2
    【网关路由测试】——路由表一致性测试
  • 原文地址:https://blog.csdn.net/AiTTTTTT/article/details/126064611