一、創(chuàng)建私有CA并進行證書申請。
1、創(chuàng)建私有CA自簽名證書
?首先安裝openssl-libs包,查看配置文件?cat /etc/pki/tls/openssl.cnf
1-1、創(chuàng)建/etc/pki/CA目錄
[root@centos8 ~]#mkdir -pv /etc/pki/CA/{certs,crl,newcerts,private}
[root@centos8 ~]#tree /etc/pki/CA/

1-2、在/etc/pki/CA目錄下創(chuàng)建私鑰,查看私鑰文件
[root@centos8 ~]# cd /etc/pki/CA
[root@centos8 CA]#(umask 066; openssl genrsa -out private/cakey.pem 2048)
[root@centos8 CA]#cat private/cakey.pem

1-3、給CA頒發(fā)自簽名證書:
[root@centos8 ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 3650 -out /etc/pki/CA/cacert.pem

1-4、在centos上用命令將證書文件的base64編碼轉換為一個譯讀的格式進行查看證書文件
[root@centos8 ~]# openssl x509 -in /etc/pki/CA/cacert.pem -noout -text

或者將證書文件cacert.pem傳至windows桌面,修改文件名為cacert.pem.crt,雙擊可以看到下面顯示
[root@centos8 ~]#sz /etc/pki/CA/cacert.pem

2、用戶生成私鑰和證書申請
2-1、生成用戶私鑰文件
[root@centos8 ~]#mkdir /data/app1
[root@centos8 ~]#(umask 066; openssl genrsa -out ? /data/app1/app1.key 2048)
[root@centos8 ~]#cat /data/app1/app1.key

2-2、生成用戶申請文件
[root@centos8 ~]#openssl req -new -key /data/app1/app1.key -out /data/app1/app1.csr
[root@centos8 ~]#ll /data/app1/

2-3、CA頒發(fā)證書
index.txt和serial文件在頒發(fā)證書時需要使用,如果不存在會出現(xiàn)錯誤,先創(chuàng)建文件如下:
生成證書索引數(shù)據(jù)庫文件:
[root@centos8 ~]# touch /etc/pki/CA/index.txt
指定第一個頒發(fā)證書的序列號
[root@centos8 ~]# echo 0F > /etc/pki/CA/serial
通過openssl ca命令指定證書申請文件的路徑:/data/app1/app1.csr
再通過-out指定輸出路徑/etc/pki/CA/certs/app1.crt,指定證書有效期1000天 -days 1000
[root@centos8 ~]# openssl ca -in /data/app1/app1.csr -out /etc/pki/CA/certs/app1.crt -days 1000

查看證書:
[root@centos8 ~]# cat /etc/pki/CA/certs/app1.crt
查看證書表調:
[root@centos8 ~]# openssl x509 -in /etc/pki/CA/certs/app1.crt -noout -issuer
查看給誰頒發(fā)的證書:
[root@centos8 ~]# openssl x509 -in /etc/pki/CA/certs/app1.crt -noout -subject
查看證書有效期:
[root@centos8 ~]# openssl x509 -in /etc/pki/CA/certs/app1.crt -noout -dates
查看證書序列號:
[root@centos8 ~]# openssl x509 -in /etc/pki/CA/certs/app1.crt -noout -serial
查看證書的有效性:
[root@centos8 ~]# openssl ca -status 0F

3、將證書相關文件發(fā)送至客戶端使用
[root@centos8 data]# cp /etc/pki/CA/certs/app1.crt /data/app1/
至此CA頒發(fā)證書的整個過程已經(jīng)完成,下面是有關CA證書的一些其他功能和用法.
*、給第二家單位頒發(fā)證書,則執(zhí)行2-1開始的步驟(文件路徑改一下),如果默認必須一致的三項(國家,地區(qū),機構)有不一樣的地方則會報錯。解決方法有兩種:1、將app1.csr文件重新生成。2、修改openssl的配置文件
修改openssl配置文件
[root@centos8 ~]# vim /etc/pki/tls/openssl.cnf

*、一個證書申請多個證書文件的方法:
[root@centos8 ~]# vim /etc/pki/CA/index.txt.attr
執(zhí)行2-3的命令,將申請的文件名換一下
[root@centos8 ~]# openssl ca -in /data/app1/app1.csr -out /etc/pki/CA/certs/app1-2.crt -days 1000

*、吊銷證書的方法:
查看證書文件的信息,得出證書編號11
[root@centos8 ~]# cat /etc/pki/CA/index.txt吊銷證書編號為11的證書文件
[root@centos8 ~]# openssl ca -revoke /etc/pki/CA/newcerts/11.pem

生成證書吊銷列表文件
指定第一個吊銷證書的編號,注意:第一次更新證書吊銷列表前,才需要執(zhí)行
[root@centos8 ~]# echo 01 > /etc/pki/CA/crlnumber
更新證書吊銷列表
[root@centos8 ~]# openssl ca -gencrl -out /etc/pki/CA/crl.pem
查看crl文件:
[root@centos8 ~]# openssl crl -in /etc/pki/CA/crl.pem -noout -text
#將此文件crl.pem傳到windows上并改后綴為crl.pem.crl,雙擊可以查看以下顯示
[root@centos8 ~]#sz /etc/pki/CA/crl.pem?


*非交互式申請證書方法

二、總結ssh常用參數(shù)、用法
ssh命令是ssh客戶端,允許實現(xiàn)對遠程系統(tǒng)經(jīng)驗證地加密安全訪問。ssh客戶端配置文件是:/etc/ssh/ssh_config
ssh命令配合的常見選項:
-p port:遠程服務器監(jiān)聽的端口
?ssh 192.168.1.8 -p 2222
-b 指定連接的源IP
ssh 192.168.1.8 -p 2222 -b 192.168.1.88
-v 調試模式
ssh 192.168.1.8 -p 2222 -v
-C 壓縮方式
-X 支持x11轉發(fā)
支持將遠程linux主機上的圖形工具在當前設備使用
-t 強制偽tty分配,如:ssh -t remoteserver1 ssh -t remoteserver2 ? ssh ?
remoteserver3
-o option ? 如:-o StrictHostKeyChecking=no
-i <file> 指定私鑰文件路徑,實現(xiàn)基于key驗證,默認使用文件: ~/.ssh/id_dsa,
~/.ssh/id_ecdsa, ~/.ssh/id_ed25519,~/.ssh/id_rsa等
三、總結sshd服務常用參數(shù)、用法
服務器端的配置文件: /etc/ssh/sshd_config
常用參數(shù):
Port? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#端口號
ListenAddress ipLoginGraceTime 2m? ? ? ? ? ? #寬限期
PermitRootLogin yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #默認ubuntu不允許root遠程ssh登錄
StrictModes yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#檢查.ssh/文件的所有者,權限等
MaxAuthTries ??6? ? ?
MaxSessions ?10? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#同一個連接最大會話
PubkeyAuthentication yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#基于key驗證
PermitEmptyPasswords no? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#空密碼連接
PasswordAuthentication yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#基于用戶名和密碼連接
GatewayPorts no
ClientAliveInterval 10? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #單位:秒
ClientAliveCountMax 3? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#默認3
UseDNS yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#提高速度可改為no
GSSAPIAuthentication yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #提高速度可改為no
MaxStartups? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#未認證連接最大值,默認值10
Banner /path/file
#以下可以限制可登錄用戶的辦法:
AllowUsers user1 user2 user3
DenyUsers
AllowGroups
ssh服務的最佳實踐
建議使用非默認端口
禁止使用protocol version 1
限制可登錄用戶
設定空閑會話超時時長
利用防火墻設置ssh訪問策略僅監(jiān)聽特定的IP地址
基于口令認證時,使用強密碼策略,比如:tr -dc A-Za-z0-9_ < /dev/urandom | head -c 12|
xargs
使用基于密鑰的認證
禁止使用空密碼
禁止root用戶直接登錄
限制ssh的訪問頻度和并發(fā)在線數(shù)
經(jīng)常分析日志