一、創(chuàng)建私有CA并進(jìn)行證書申請躲因。
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編碼轉(zhuǎn)換為一個譯讀的格式進(jìn)行查看證書文件
[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
查看證書表調(diào):
[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、將證書相關(guān)文件發(fā)送至客戶端使用
[root@centos8 data]# cp /etc/pki/CA/certs/app1.crt /data/app1/
至此CA頒發(fā)證書的整個過程已經(jīng)完成狭握,下面是有關(guān)CA證書的一些其他功能和用法.
*闪金、給第二家單位頒發(fā)證書,則執(zhí)行2-1開始的步驟(文件路徑改一下)哥牍,如果默認(rèn)必須一致的三項(xiàng)(國家毕泌,地區(qū)喝检,機(jī)構(gòu))有不一樣的地方則會報(bào)錯嗅辣。解決方法有兩種: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?
*非交互式申請證書方法
二仔夺、總結(jié)ssh常用參數(shù)、用法
ssh命令是ssh客戶端攒砖,允許實(shí)現(xiàn)對遠(yuǎn)程系統(tǒng)經(jīng)驗(yàn)證地加密安全訪問缸兔。ssh客戶端配置文件是:/etc/ssh/ssh_config
ssh命令配合的常見選項(xiàng):
-p port:遠(yuǎn)程服務(wù)器監(jiān)聽的端口
?ssh 192.168.1.8 -p 2222
-b 指定連接的源IP
ssh 192.168.1.8 -p 2222 -b 192.168.1.88
-v 調(diào)試模式
ssh 192.168.1.8 -p 2222 -v
-C 壓縮方式
-X 支持x11轉(zhuǎn)發(fā)
支持將遠(yuǎn)程linux主機(jī)上的圖形工具在當(dāng)前設(shè)備使用
-t 強(qiáng)制偽tty分配,如:ssh -t remoteserver1 ssh -t remoteserver2 ? ssh ?
remoteserver3
-o option ? 如:-o StrictHostKeyChecking=no
-i <file> 指定私鑰文件路徑吹艇,實(shí)現(xiàn)基于key驗(yàn)證惰蜜,默認(rèn)使用文件: ~/.ssh/id_dsa,
~/.ssh/id_ecdsa, ~/.ssh/id_ed25519,~/.ssh/id_rsa等
三受神、總結(jié)sshd服務(wù)常用參數(shù)抛猖、用法
服務(wù)器端的配置文件: /etc/ssh/sshd_config
常用參數(shù):
Port? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#端口號
ListenAddress ipLoginGraceTime 2m? ? ? ? ? ? #寬限期
PermitRootLogin yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #默認(rèn)ubuntu不允許root遠(yuǎn)程ssh登錄
StrictModes yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#檢查.ssh/文件的所有者,權(quán)限等
MaxAuthTries ??6? ? ?
MaxSessions ?10? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#同一個連接最大會話
PubkeyAuthentication yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#基于key驗(yàn)證
PermitEmptyPasswords no? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#空密碼連接
PasswordAuthentication yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#基于用戶名和密碼連接
GatewayPorts no
ClientAliveInterval 10? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #單位:秒
ClientAliveCountMax 3? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#默認(rèn)3
UseDNS yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#提高速度可改為no
GSSAPIAuthentication yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #提高速度可改為no
MaxStartups? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#未認(rèn)證連接最大值鼻听,默認(rèn)值10
Banner /path/file
#以下可以限制可登錄用戶的辦法:
AllowUsers user1 user2 user3
DenyUsers
AllowGroups
ssh服務(wù)的最佳實(shí)踐
建議使用非默認(rèn)端口
禁止使用protocol version 1
限制可登錄用戶
設(shè)定空閑會話超時時長
利用防火墻設(shè)置ssh訪問策略僅監(jiān)聽特定的IP地址
基于口令認(rèn)證時财著,使用強(qiáng)密碼策略,比如:tr -dc A-Za-z0-9_ < /dev/urandom | head -c 12|
xargs
使用基于密鑰的認(rèn)證
禁止使用空密碼
禁止root用戶直接登錄
限制ssh的訪問頻度和并發(fā)在線數(shù)
經(jīng)常分析日志