1. 程式人生 > >Linux openssl 證書管理

Linux openssl 證書管理

公鑰與金鑰應用的兩種情形

  • 用於資料加密
    • 兩個人:Bob和Alice;Bob有自己的公鑰和私鑰,他把公鑰公佈給大家;當Alice給Bob傳送資料時,她使用Bob的公鑰加密這些資料;因為使用Bob的公鑰加密的資料只有Bob的私鑰能解密,所以Alice傳送給Bob的資料只有Bob能解密並檢視,其他人是不能解密的(除非他有Bob的私鑰)。
  • 用於認證
    • Bob和Alice通訊,Bob如何向Alice證明自己就是Bob呢?Bob可以向Alice發一段用自己的私鑰加密的內容,如果Alice可以使用Bob的公鑰解密說明對方是Bob。
  • 這兩種情形有一個比較明顯的問題:Alice怎麼收到Bob公佈的公鑰?Alice怎麼知道自己收到的公鑰就是Bob的公鑰?這個時候就需要第三方來認證了,那就是數字證書。

數字證書

  • 上面提到的只是對公鑰和私鑰的簡單說明,實際過程很複雜,所以後來才發展出了數字證書,數字證書就是用來數字證書傳送方證明數字證書持有人的。以Bob和Alice為例,就是Bob向Alice證明自己就是Bob的。數字證書也是由公認的權威機構頒發的,而且這些機構會給自己生成一個數字證書,這些機構的數字證書被預製安裝在作業系統中被用來對其他伺服器發來的證書進行認證;
  • 購買這些機構發行的數字證書價格不菲,我們能否自己私建證書對自己內部的主機進行認證呢?能!

私建數字證書

  • 需要一臺管理證書的伺服器,比如我有一臺centos7伺服器;
    • 用到的程式:openssl;
    • 配置檔案:
[[email protected] pki]# ll /etc/pki/tls/openssl.cnf 
-rw-r--r--. 1 root root 10923 Mar  5  2015 /etc/pki/tls/openssl.cnf
  • 主目錄結構:
[root@mylinux7 ~]# ll /etc/pki/CA/
    # /etc/pki/CA/,Where everything is kept;
total 24
drwxr-xr-x. 2 root root 4096 Mar  5  2015 certs
    # certs,Where the issued certs are kept;
drwxr-xr-x. 2 root root 4096 Mar 5 2015 crl # crl(吊銷證書列表),Where the issued crl are kept; -rw-r--r--. 1 root root 3 Jan 4 18:49 crlnumber # crlnumber,the current crl number; -rw-r--r--. 1 root root 0 Jan 4 18:47 index.txt # index.txt,database index file; drwxr-xr-x. 2 root root 4096 Mar 5 2015 newcerts # newcerts,default place for new certs; drwx------. 2 root root 4096 Mar 5 2015 private # private,證書發現伺服器本身私鑰cakey.pem的存放目錄; -rw-r--r--. 1 root root 3 Jan 4 18:48 serial # serial,The current serial number; 注: crlnumber,index.txt,serial這三個檔案需要新建(依據是配置檔案): [root@mylinux7 ~]# cd /etc/pki/CA/ [root@mylinux7 CA]# touch index.txt [root@mylinux7 CA]# echo 01 > serial [root@mylinux7 CA]# echo 01 > crlnumber
  • CA伺服器自簽證書過程(給自己發行證書):
[[email protected] CA]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
    # 此語句是以077的umask生成一個cakey.pem私鑰檔案;
Generating RSA private key, 2048 bit long modulus
................+++
...............................................................................+++
e is 65537 (0x10001)
[[email protected] CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc
/pki/CA/cacert.pem
    # 可能您看到的是換行的,其實是一條語句;
    # openssl req 用於生成證書請求檔案;
    # -new 生成新證書籤署請求;
    # -x509 專用於CA生成自簽證書;
    # -key 生成請求檔案時用到的私鑰檔案;
    # days 證書的有效期限,以“天”為單位;
    # -out 證書的儲存路徑;
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]:CN
    # 國家名,兩個字元;
State or Province Name (full name) []:Shanghai
    # 省名或州名;
Locality Name (eg, city) [Default City]:Shanghai
    # 城市名;
Organization Name (eg, company) [Default Company Ltd]:TestCompany
    # 公司名;
Organizational Unit Name (eg, section) []:web
    # 部門名稱;
Common Name (eg, your name or your server's hostname) []:mylinux7
    # 你的名字或伺服器名;
Email Address []:[email protected]
    # 你的Email地址;
[[email protected] CA]# ll /etc/pki/CA/cacert.pem 
-rw-r--r--. 1 root root 1411 Jan  5 04:48 /etc/pki/CA/cacert.pem
    # cacert.pem為CA的自簽證書;
  • 給其他主機發行證書
    • 我這裡是給如下主機發行證書
[[email protected] ~]# hostname
dns1.mysite.com
  • 首先申請方伺服器得生成一個私鑰,並利用私鑰生成一個請求檔案:
[[email protected] ~]# (umask 077; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)
    # 使用rsa演算法生成一個私鑰;
Generating RSA private key, 2048 bit long modulus
....................+++
..........................................+++
e is 65537 (0x10001)
[[email protected] ~]# openssl req -new -key /etc/httpd/ssl/httpd.key -days 365 -out /etc/httpd/ssl/httpd.csr
    # 使用剛生成的一個私鑰再生成一個請求檔案httpd.csr
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]:CN
State or Province Name (full name) []:Shanghai
Locality Name (eg, city) [Default City]:Shanghai
Organization Name (eg, company) [Default Company Ltd]:TestCompany
Organizational Unit Name (eg, section) []:web
Common Name (eg, your name or your server's hostname) []:www        
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[[email protected] ~]# ll /etc/httpd/ssl/httpd.csr 
-rw-r--r--. 1 root root 1054 Jan  8 20:41 /etc/httpd/ssl/httpd.csr
  • 把檔案通過某個方法傳送(傳送)給CA伺服器
    • 由於是測試環境,我使用的是scp命令:
[[email protected] ~]# scp /etc/httpd/ssl/httpd.csr [email protected]:/tmp/httpd.csr
The authenticity of host '192.168.1.105 (192.168.1.105)' can't be established.
RSA key fingerprint is 6c:3e:a2:06:52:e4:e4:b9:82:52:74:fc:0a:44:ea:6d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.105' (RSA) to the list of known hosts.
[email protected]192.168.1.105's password: 
httpd.csr                                                       100% 1054     1.0KB/s   00:00
  • 在CA伺服器生成申請伺服器的證書
[root@mylinux7 CA]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365 
    # 使用openssl ca命令生成證書;
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Jan  5 10:51:28 2016 GMT
            Not After : Jan  4 10:51:28 2017 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = Shanghai
            organizationName          = TestCompany
            organizationalUnitName    = web
            commonName                = www
            emailAddress              = root@dns1.mysite.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                A4:CF:3A:18:D8:EE:08:54:11:18:DC:CD:A0:5B:17:F9:40:E1:8C:D4
            X509v3 Authority Key Identifier: 
                keyid:DA:48:EB:1E:B2:36:DA:44:E7:3C:53:A9:47:62:D7:FD:5A:E4:D1:8D

Certificate is to be certified until Jan  4 10:51:28 2017 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@mylinux7 CA]# scp /etc/pki/CA/certs/httpd.crt [email protected]:/etc/httpd/ssl/httpd.crt
root@192.168.1.108's password: 
httpd.crt                                                       100% 4606     4.5KB/s   00:00
    # 使用scp命令將證書傳送回申請伺服器;
  • 可以發現CA伺服器CA目錄下的index.txt和serial檔案內容已經更新,且在newcert目錄下也生成了一個名字為01的證書;
  • 在申請到證書的伺服器上可以通過如下命令檢視證書資訊:
[root@dns1 ~]# openssl x509 -in /etc/httpd/ssl/httpd.crt -noout -serial -subject -text
    # 最後的-serial -subject -text三者可以根據需要任意出現;
  • 吊銷證書
    • 申請到證書的伺服器應該首先使用上面提到的命令提取自己證書的serial和subject,併發送給CA伺服器;
    • CA伺服器收到serial和subject,與index.txt中的證書資訊進行校驗,通過則執行吊銷:
[[email protected] CA]# openssl ca -revoke /etc/pki/CA/newcerts/01.pem 
    # 吊銷證書命令“01”是serial;
Using configuration from /etc/pki/tls/openssl.cnf
Revoking Certificate 01.
Data Base Updated
You have new mail in /var/spool/mail/root
[[email protected] CA]# openssl ca -gencrl -out myca.crl
    # 更新證書吊銷列表;
Using configuration from /etc/pki/tls/openssl.cnf

–完–

相關推薦

Linux openssl 證書管理

公鑰與金鑰應用的兩種情形 用於資料加密 兩個人:Bob和Alice;Bob有自己的公鑰和私鑰,他把公鑰公佈給大家;當Alice給Bob傳送資料時,她使用Bob的公鑰加密這些資料;因為使用Bob的公鑰加密的資料只有Bob的私鑰能解密,所以Alice傳送給Bo

Linux命令應用大詞典-第36章 密碼和證書管理

slap HA 命令行工具 詞典 管理員 style iges 證書 創建 36.1 pwdhash:密碼哈希生成器 36.2 mkpasswd:生成應用於用戶的新密碼 36.3 keytool:密鑰和證書管理工具 36.4 certutil:證書服務器管理工具 36.5

linux安全和加密篇(四)—openssl證書申請和建立CA

OpenSSL證書申請 1、PKI: Public Key Infrastructure CA            證書頒發機構 RA            證書請求機構 request CRL          2、建立私有CA: 搭建CA OpenCA

Linux openssl 生成證書的詳解

目錄 前言 1 概念 2 環境 4 頒發證書 5 測試 前言 最近,被分配了一個任務,完成數字證書管理系統的開發,一開始我是一臉懵逼的,因為以前我對於什麼數字證書都沒了解過,可謂了一片空白,也不知其是用來幹嘛的。於是,我奮發圖強,用了一個下午

linux ca-certificates維護openssl證書

SSL證書的維護由ca-certificates來提供支援 https://packages.debian.org/source/sid/ca-certificates Debian 軟體包原始碼倉庫(VCS: Git) https://anonscm.debian.

Linux下如何根據域名自簽發OpenSSL證書與常用證書轉換

  在Linux下如何根據域名自簽發各種SSL證書,這裡我們以Apache、Tomcat、Nginx為例。   openssl自簽發泛域名(萬用字元)證書 首先要有openssl工具,如果沒有那麼使用如下命令安裝: yum install -y openssl openssl-dev

Linux存儲管理及硬盤分區、格式化、掛載

硬盤接口 mknod fdisk 下面介紹的是Linux的存儲管理基礎知識、使用一個新的硬盤設備步驟為(分區、格式化、掛載分區)。一、Linux的存儲管理基礎知識點1、硬件組成計算機基礎知識中,各個硬件表示為:運算器(CUP);控制器(MEEM);硬盤(HDisk);網卡(NIC,即net int

linux job control管理

管理 使用 stopped 會有 nbsp pid bash top span   bash只能管理自己的工作而不能管理其他bash的工作,即使是root用戶也無法做到.bash的工作分為前臺與後臺. 我們在只有一個bash的環境情況下,如果要同時進行多個進程工作,那麽可以

Linux】系統管理

kcon status gcc 不知道 切換 all usr make entos 軟件包管理 一 軟件包分類  源碼包: .tar.gz .tar.bz2   二進制包: .rpm 二 二進制包安裝   (一) rpm命令手動管理二進制包 (掛載光盤)

Linux深度攻略》一書,講述Linux日常系統管理和服務器配置內容

linuxLinux深度攻略 首先從介紹Linux系統的安裝入手,講述了Linux系統管理和服務器配置兩部分的知識。系統管理方面內容有Linux系統簡介和安裝,Linux字符界面,目錄和文件管理,Linux常用命令,Shell編程,用戶和組群賬戶管理,權限、所有者和ACL,歸檔、壓縮和備份,軟件包管理,磁盤和

linux進程管理

linux 進程管理 我們在使用任何操作系統的時候都會打開一些應用程序,那麽打開程序就會開啟一個進程,我們在使用windows系統的時候,有時候開一個QQ,同時開一個遊戲,還可以打開音樂播放軟件,打開程序過多會消耗大量的內存和cpu是得系統有時候會感覺很卡頓,那麽在Linux下如何管理進程呢,接下跟大家分

Linux存儲管理(2)

linux 空間 能力 用戶 RAID磁盤陣列,簡稱獨立磁盤冗余陣列。可以將多個硬盤按不同方式組合在一起形成一個硬盤組,從而產生比單個硬盤更高的存儲行能和數據備份功能;使多個磁盤實現並行讀寫;擁有容錯能力;用戶可以對組成的硬盤組進行格式化,掛載等操作,與單個硬盤的操作一模一樣,但其存儲速度

第一篇:linux系統應用管理之用戶的切換

修改用戶、用戶切換、添加普通用戶、系統應用管理管理Linux系統運維之前,先來查看一下當前Linux系統的版本、內核等信息。命令如下:[[email protected]/* */ ~]# cat /etc/redhat-release CentOS release 6.8 (Final)

Linux 磁盤管理

創建交換分區 硬件 ext 移除 創建邏輯卷 linux文件系統 文件系統類型 linu 退出 1、創建磁盤分區 fdisk /dev/vda1 p: 顯示當前硬件的分區,包括沒保持的改動 n: 創建新分區 d:刪除

Linux存儲管理(3)

可擴展性 linux 下一代 開發 動態 之前詳細講述了如何進行磁盤管理,對所創建的磁盤創建文件系統,對其進行邏輯上的編址,主要講了ext系列的文件系統,今天在這裏總結一下,關於當前Linux文件系統中發展較為迅速的btrfs文件系統,btrfs開發目的就是取代ext系列文件系統,成為

Linux遠程管理器xshell和xftp使用教程

win ssh1 ros html ssh nbsp ssh2 tel 基於 1.xshell 是一個強大的安全終端模擬軟件,它支持SSH1, SSH2, 以及Microsoft Windows 平臺的TELNET 協議。 2.是一個基於 MS windows 平臺的功能強

Linux內存管理機制

訪問性 內存操作 內存管理 保存 說明 容量 分隔 命令 font 一、首先大概了解一下計算機CPU、Cache、內存、硬盤之間的關系及區別。 1、 CPU也稱為中央處理器(CPU,Central Processing Unit)是一塊超大規模的集成電

linux磁盤管理

互聯網 linux 服務器 數據庫 固態硬盤 liunx磁盤管理1、第一塊硬盤/dev/sda 第二塊/dev/sdb 第三塊/dev/sbc裝系統之前一般都裝RAID,LVM不常用分區---->格式化—>掛載磁盤第一個分區/dev/sda1 以此類推2、磁盤分類:機械盤、

Linux用戶管理命令

新用戶 詳細 用戶信息 查看 tty 負載 lin png 用戶管理 1、名稱:useradd 功能:添加新用戶 範例: $useradd yangmi 2、名稱:passwd 功能描述:設置用戶密碼 範例 $passwd yangmi 3、名稱:who 功能描述:

Linux進程管理 - PRI,nice,free,uname,netstat

table 內存不足 不一定 影響 表示 order net 喚醒 總計 優先執行序 (priority, PRI) 這個 PRI 值越低代表越優先的意思。只是這個 PRI 值是由核心動態調整的, 使用者無法直接調整