第八周

2021/8/23 23:07:54

本文主要是介绍第八周,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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

1.创建CA所需要文件
#生成证书索引数据库文件
touch /etc/pki/CA/index.txt
#指定第一个颁发证书的序列号
echo 01 > /etc/pki/CA/serial

2、 生成CA私钥
cd /etc/pki/CA/
(umask 066; openssl genrsa -out private/cakey.pem 2048)
3、生成CA自签名证书
openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 3650 -out
/etc/pki/CA/cacert.pem
##直接生成不用交互式

openssl req -utf8 -newkey rsa:1024 -subj "/CN=www.magedu.org" -
keyout app.key -nodes -x509 -out app.crt
选项说明:
-new:生成新证书签署请求
-x509:专用于CA生成自签证书
-key:生成请求时用到的私钥文件
-days n:证书的有效期限
-out /PATH/TO/SOMECERTFILE: 证书的保存路径
centos7 直接生成自签名证书
cd /etc/pki/tls/certs
make /date/httpd.crt
make /date/httpd.key
输入信息可以直接在/date下生成自签名证书是由目录下的Makefile文件直接生成
二、用户生成私钥和证书申请
mkdir /data/app1 #比如date下的应用APP1需要申请证书
1.(umask 066; openssl genrsa -out /data/app1/app1.key 2048) #生成私钥文件

2.openssl req -new -key /data/app1/app1.key -out /data/app1/app1.csr #生成证书申请文件

#默认有三项内容必须和自签名CA一致:国家,省份,组织,如果不同,会出现下面的提示

Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
The stateOrProvinceName field is different between
CA certificate (beijing) and the request (hubei)

三CA颁发证书
openssl ca -in /date/app1/app1.csr -out /etc/pki/CA/certs/app1.crt -days 1000
tree /etc/pki/CA/
/etc/pki/CA/
├── cacert.pem
├── certs
│   └── app1.crt
├── crl
├── index.txt
├── index.txt.attr
├── index.txt.old
├── newcerts
│   └── 01.pem
├── private
│   └── cakey.pem
├── serial
└── serial.old

cat /etc/pki/CA/index.txt
V 240430141751Z 01 unknown /C=CN/ST=guangdong/O=linux/OU=www.zhang.com/CN=www.zhang.com

查看证书有效性
openssl ca -status 01
2、总结ssh常用参数、用法
1、连接到远程主机:

命令格式 :

ssh name@remoteserver 或者

ssh remoteserver -l name

说明:以上两种方式都可以远程登录到远程主机,server代表远程主机,name为登录远程主机的用户名。

2、连接到远程主机指定的端口:

命令格式:

ssh name@remoteserver -p 2222 或者

ssh remoteserver -l name –p 2222

说明:p 参数指定端口号,通常在路由里做端口映射时,我们不会把22端口直接映射出去,而是转换成其他端口号,这时就需要使用-p 端口号命令格式。

3、通过远程主机1跳到远程主机2:

命令格式:

ssh -t remoteserver1 ssh remoteserver2

说明:当远程主机remoteserver2无法直接到达时,可以使用-t参数,然后由remoteserver1跳转到remoteserver2。在此过程中要先输入remoteserver1的密码,然后再输入remoteserver2的密码,然后就可以操作remoteserver2了。

4、通过SSH运行远程shell命令:

命令格式:

ssh -l name remoteserver ‘command’

说明:连接到远程主机,并执行远程主机的command命令。例如:查看远程主机的内存使用情况。

$ ssh –l root 192.168.1.100 svmon –G

www.2cto.com

5、修改SSH监听端口:

默认情况下,SSH监听连接端口22,攻击者使用端口扫描软件就可以看到主机是否

运行有SSH服务,将SSH端口修改为大于1024的端口是一个明智的选择,因为大多数端口扫描软件(包括nmap)默认情况都不扫描高位端口。打开/etc/ssh/sshd_config文件并查找下面这样的行:

Port  22

去掉该行前面的# 号,然后修改端口号并重新启动SSH服务:

$ /etc/init.d/ssh restart


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
4、搭建dhcp服务,实现ip地址申请分发
yum -y install dhcp
#安装的dhcp服务需要修改配置文件
vim /etc/dhcp/dhcpd.conf
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers 8.8.8.8, 114.114.114.114;
#DNS地址

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 192.168.75.0 netmask 255.255.255.0 #网段和子网掩码
{
range 192.168.75.141 192.168.75.180;#地址范围
option routers 192.168.75.2;#网关
next-server 192.168.1.100; #TFTP服务器地址
filename "pxelinux.0"; #bootloader启动文件的名称
}
# DHCP服务器给指定主机分配固定IP
host test {
hardware ethernet 00:0c:29:cd:90:10;
fixed-address 10.0.0.123; #固定ip
}
#写好配置文件需重启dhcp服务

#dhcp 客户端申请地址的过程
dhclient -d
#DHCP服务器的日志
[root@centos8 ~]#tail -f /var/lib/dhcpd/dhcpd.leases
#DHCP客户端的日志
[root@centos7 ~]#ls /var/lib/dhclient/
dhclient.leases
[root@centos7 ~]#cat /var/lib/dhclient/dhclient.leases



这篇关于第八周的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程