溫馨提示×

Linux OpenSSL如何配置訪問控制

小樊
53
2025-04-25 22:00:46
欄目: 云計算

在Linux系統中,使用OpenSSL配置訪問控制通常涉及以下幾個方面:

  1. 證書頒發機構(CA)配置

    • 創建CA目錄結構。
    • 生成CA私鑰和自簽名CA證書。
    • 配置CA證書吊銷列表(CRL)。
  2. 服務器證書和密鑰配置

    • 生成服務器私鑰。
    • 生成服務器證書簽名請求(CSR)。
    • 使用CA簽發服務器證書。
  3. 客戶端證書配置

    • 生成客戶端私鑰。
    • 生成客戶端證書簽名請求(CSR)。
    • 使用CA簽發客戶端證書。
  4. 訪問控制列表(ACL)配置

    • 在服務器配置文件中設置客戶端證書驗證。
    • 使用OpenSSL的verify命令驗證客戶端證書。

以下是一個基本的步驟指南:

1. 創建CA目錄結構

mkdir -p /etc/ssl/CA/newcerts
echo 1000 > /etc/ssl/CA/serial
touch /etc/ssl/CA/index.txt
chmod 640 /etc/ssl/CA/index.txt
mkdir /etc/ssl/CA/certs
mkdir /etc/ssl/CA/private
chmod 700 /etc/ssl/CA/private

2. 生成CA私鑰和自簽名CA證書

openssl genpkey -algorithm RSA -out /etc/ssl/CA/private/ca.key 4096
openssl req -x509 -new -nodes -key /etc/ssl/CA/private/ca.key -sha256 -days 1024 -out /etc/ssl/CA/certs/ca.crt -subj "/C=US/ST=State/L=City/O=Organization/CN=CA"

3. 生成服務器私鑰和CSR

openssl genpkey -algorithm RSA -out server.key 2048
openssl req -new -key server.key -out server.csr -subj "/C=US/ST=State/L=City/O=Organization/CN=server.example.com"

4. 使用CA簽發服務器證書

openssl x509 -req -in server.csr -CA /etc/ssl/CA/certs/ca.crt -CAkey /etc/ssl/CA/private/ca.key -CAcreateserial -out server.crt -days 500 -sha256

5. 生成客戶端私鑰和CSR

openssl genpkey -algorithm RSA -out client.key 2048
openssl req -new -key client.key -out client.csr -subj "/C=US/ST=State/L=City/O=Organization/CN=client.example.com"

6. 使用CA簽發客戶端證書

openssl x509 -req -in client.csr -CA /etc/ssl/CA/certs/ca.crt -CAkey /etc/ssl/CA/private/ca.key -CAcreateserial -out client.crt -days 500 -sha256

7. 配置服務器訪問控制

編輯服務器配置文件(例如/etc/ssl/openssl.cnf),添加以下內容:

[ ca ]
default_ca = CA_default

[ CA_default ]
dir               = /etc/ssl/CA
certs             = $dir/certs
crl_dir           = $dir/crl
new_certs_dir     = $dir/newcerts
database          = $dir/index.txt
serial            = $dir/serial
RANDFILE          = $dir/private/.rand

[ req ]
default_bits        = 2048
distinguished_name  = req_distinguished_name
string_mask         = utf8only

[ req_distinguished_name ]
countryName                     = Country Name (2 letter code)
stateOrProvinceName             = State or Province Name
localityName                    = Locality Name
organizationName                = Organization Name
commonName                      = Common Name

[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

8. 配置服務器SSL/TLS

編輯服務器SSL/TLS配置文件(例如/etc/httpd/conf.d/ssl.conf/etc/nginx/sites-available/default-ssl),添加以下內容:

<VirtualHost _default_:443>
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/server.crt
    SSLCertificateKeyFile /etc/ssl/private/server.key
    SSLCACertificateFile /etc/ssl/certs/ca.crt
    SSLVerifyClient require
    SSLVerifyDepth 10
</VirtualHost>

9. 驗證客戶端證書

使用OpenSSL的verify命令驗證客戶端證書:

openssl verify -CAfile /etc/ssl/certs/ca.crt client.crt

通過以上步驟,你可以配置OpenSSL以實現訪問控制,確保只有持有有效客戶端證書的用戶才能訪問服務器。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女