第十四周作业

1、创建私有CA并进行证书申请。

1.1、 创建CA相关目录和文件

[root@centos8 ~]# mkdir -pv /etc/pki/CA/{certs,crl,newcerts,private}
[root@centos8 ~]# touch /etc/pki/CA/index.txt
[root@centos8 ~]# echo 01 > /etc/pki/CA/serial

1.2、创建CA的私钥

[root@centos8 ~]# cd /etc/pki/CA/
[root@centos8 ~]# (umask 066; openssl genrsa -out private/cakey.pem 2048)

1.3、给CA颁发自签名证书

[root@centos8 ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 3650 -out /etc/pki/CA/cacert.pem
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) []:zhejiang
Locality Name (eg, city) [Default City]:hangzhou
Organization Name (eg, company) [Default Company Ltd]:ddq
Organizational Unit Name (eg, section) []:devops
Common Name (eg, your name or your server's hostname) []:ca.ddq.org
Email Address []:admin@ddq.org

1.4、用户生成私钥和证书申请文件

[root@centos8 ~]# mkdir /data1/app1
[root@centos8 ~]# (umask 066; openssl genrsa -out /data1/app1/app1.key 2048)
[root@centos8 ~]# req -new -key /data1/app1/app1.key -out /data1/app1/app1.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) []:zhejiang
Locality Name (eg, city) [Default City]:hangzhou
Organization Name (eg, company) [Default Company Ltd]:ddq
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:app1.ddq.org
Email Address []:root@ddq.org

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

#默认有三项内容必须和CA一致:国家,省份,组织

1.5、 CA颁发证书

[root@centos8 ~]# openssl ca -in /data1/app1/app1.csr -out /etc/pki/CA/certs/app1.crt -days 1000
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: Jun 22 01:39:46 2021 GMT
            Not After : Mar 18 01:39:46 2024 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = zhejiang
            organizationName          = ddq
            organizationalUnitName    = it
            commonName                = app1.ddq.org
            emailAddress              = root@ddq.org
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                A9:62:68:F2:83:26:04:EE:DC:E9:08:D2:73:87:10:74:5F:73:7A:39
            X509v3 Authority Key Identifier:
                keyid:AA:44:47:6C:3B:EC:B8:F8:35:A9:09:45:C8:B3:F7:CB:31:1A:9C:7E

Certificate is to be certified until Mar 18 01:39:46 2024 GMT (1000 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

1.6、 查看证书

[root@centos8 ~]# openssl x509 -in /etc/pki/CA/certs/app1.crt -noout -text
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 1 (0x1)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=CN, ST=zhejiang, L=hangzhou, O=ddq, OU=devops, CN=ca.ddq.org/emailAddress=admin@ddq.org
        Validity
            Not Before: Jun 22 01:39:46 2021 GMT
            Not After : Mar 18 01:39:46 2024 GMT
        Subject: C=CN, ST=zhejiang, O=ddq, OU=it, CN=app1.ddq.org/emailAddress=root@ddq.org
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:bb:c1:52:91:5a:23:f7:30:29:03:d8:9b:fe:41:
                    02:99:e0:75:8d:88:33:87:96:26:89:d4:02:84:c6:
                    2f:6b:c9:b4:37:0c:b5:dc:a9:fc:3e:19:24:d8:38:
                    83:88:2f:b0:e6:55:00:76:bb:38:33:12:5a:ac:eb:
                    f6:7f:8a:1b:3b:79:e0:60:25:71:3d:7f:6d:88:aa:
                    77:58:c0:29:72:e3:d8:16:53:66:8c:d3:f6:c7:1b:
                    75:94:ea:e1:58:8c:27:ba:41:74:7c:1c:1f:38:f8:
                    b4:c7:17:6b:b2:68:7f:ec:b8:7f:ac:4a:d0:a5:88:
                    63:07:28:ca:0d:aa:ce:36:0b:23:4f:e4:5e:d4:dd:
                    b8:3f:a1:14:5e:e5:36:47:f9:e6:9b:ea:da:85:a7:
                    72:32:5b:54:dd:a2:2a:68:f8:65:93:da:62:28:ac:
                    cf:9b:46:56:49:e8:8e:ee:46:01:f2:67:4d:69:20:
                    2a:c3:a5:cc:c9:52:62:8f:07:3a:6c:30:49:00:8a:
                    df:7d:5a:95:d1:74:6b:a0:dc:cd:63:8e:cf:96:ff:
                    05:91:4d:9f:bd:eb:1a:00:47:90:81:c5:c6:c2:15:
                    8a:d0:6a:33:6d:d2:1f:d2:12:ed:db:68:c4:4b:b6:
                    26:4e:db:d6:a0:fc:a7:b4:06:a6:f5:f2:ed:2e:b5:
                    8a:f1
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                A9:62:68:F2:83:26:04:EE:DC:E9:08:D2:73:87:10:74:5F:73:7A:39
            X509v3 Authority Key Identifier:
                keyid:AA:44:47:6C:3B:EC:B8:F8:35:A9:09:45:C8:B3:F7:CB:31:1A:9C:7E

    Signature Algorithm: sha256WithRSAEncryption
         92:c6:c1:6a:6e:2d:df:d6:ab:ff:aa:32:6e:fc:76:7b:dc:52:
         e8:fd:2e:e9:c2:b5:fa:3d:5d:c3:0b:1f:d6:75:1d:4e:18:19:
         26:6e:13:88:df:ff:6e:56:c0:18:ea:8c:7a:95:43:e5:fd:b4:
         11:bd:c2:10:05:9e:6b:9f:bc:d6:8a:44:0a:4f:09:7a:bf:c4:
         3a:88:1c:23:29:0d:98:12:d3:ea:3c:8c:8a:31:43:7d:c4:58:
         8f:e2:96:26:91:d3:e9:c4:64:3a:f9:86:f2:0e:60:52:af:b1:
         62:59:63:3f:5c:96:82:de:a7:b0:43:4a:9d:67:aa:91:41:1e:
         86:60:ba:0f:eb:b0:32:d5:27:83:87:4f:b2:6a:07:ff:4e:c0:
         36:10:fa:46:e2:a6:39:a3:c3:35:43:46:4b:5c:9f:12:1a:8b:
         1d:90:2a:99:c4:4d:e2:70:f2:2d:c5:a4:5b:f1:80:d2:6c:ca:
         b3:d5:83:fe:86:ca:28:b2:ad:3e:c2:8f:ee:67:5c:99:45:97:
         07:8c:1c:a7:1b:6a:4e:21:86:8c:7a:f5:30:af:e5:13:1b:92:
         92:ee:3d:9c:f2:b1:6d:6a:b7:a4:32:09:49:07:35:db:c9:df:
         03:ca:6d:5b:58:d8:b4:29:9c:59:d4:5d:6a:3c:8f:23:e7:64:
         ca:ec:fd:59

#验证指定编号的对应证书有效性
[root@centos8 ~]# openssl ca -status 01
Using configuration from /etc/pki/tls/openssl.cnf
01=Valid (V)
[root@centos8 ~]# cat /etc/pki/CA/index.txt
V       240318013946Z           01      unknown /C=CN/ST=zhejiang/O=ddq/OU=it/CN=app1.ddq.org/emailAddress=root@ddq.org
[root@centos8 ~]# cat /etc/pki/CA/index.txt.old
[root@centos8 ~]# cat /etc/pki/CA/serial
02
[root@centos8 ~]# cat /etc/pki/CA/serial.old
01

1.7 将证书相关文件发送到客户端使用

[root@centos8 ~]# cp /etc/pki/CA/certs/app1.crt /data1/app1/
[root@centos8 ~]# tree /data1/app1/
/data1/app1/
├── app1.crt
├── app1.csr
└── app1.key

0 directories, 3 files

1.8 证书的信任
默认生成的证书,在windows上是不被信任的,可以通过将CA的自签名证书导入到windows的 受信任的根证书颁发机构 使私有CA签名的证书都获得windows的信任


2、总结ssh常用参数、用法

格式

ssh [user@]host [COMMAND]
ssh [-l user] host [COMMAND]

常用选项

-p port: 远程服务器监听端口
-b 指定连接的源IP
-v 调试模式
-C 压缩方式
-X 支持x11转发
-t 支持伪tty分配,如: ssh -t remoteserver1 ssh -t remoteserver2 ssh remoteserver3
-o option 如: StrictHostKeyChecking=no
-i <file> 指定私钥文件路径,实现基于key验证,默认使用文件: ~/.ssh/id_dsa,~/.ssh/id_ecdsa, ~/.ssh/id_ed25519,~/.ssh/id_rsa等


3、总结sshd服务常用参数。

常用参数

Port
ListenAddress ip
LoginGraceTime 2m
PermitRootLogin yes #默认ubuntu不允许root远程ssh登录
StrictModes yes #检查.ssh/文件的所有者,权限等
MaxAuthTries 6 #pecifies the maximum number of authentication
attempts permitted per connection. Once the number of failures reaches half
this value, additional failures are logged. The default is 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 user1 user2 user3
AllowGroups g1 g2
DenyGroups g1 g2

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,335评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,895评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,766评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,918评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,042评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,169评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,219评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,976评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,393评论 1 304
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,711评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,876评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,562评论 4 336
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,193评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,903评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,142评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,699评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,764评论 2 351

推荐阅读更多精彩内容

  • 一、创建私有CA并进行证书申请。 1、创建私有CA自签名证书 首先安装openssl-libs包,查看配置文件ca...
    亨利阅读 366评论 1 1
  • 1、创建私有CA并进行证书申请。 2、总结ssh常用参数、用法 用法:1.远程登录口令登录(1) ssh us...
    紫火红云阅读 332评论 1 0
  • 1、导入hellodb.sql生成数据库 [root@centos7 ~]# mysql -p < hellodb...
    Gustav_man阅读 105评论 0 0
  • 1、创建私有CA并进行证书申请。 2、总结ssh常用参数、用法 3、总结sshd服务常用参数
    陌路残蝉阅读 250评论 0 0
  • 1、 导入hellodb.sql生成数据库 (1) 在students表中,查询年龄大于25岁,且为男性的同学的名...
    毅_阅读 171评论 0 0