SElinux强制安全 linux
加密与解密技术 git
CA数字证书服务 算法
标准Lunux安全模型 vim
DAC自主访问控制 Discretionary Access Control 全部都对本身的资源负责 安全
典型的DAC应用 服务器
9位权限码 网络
ACL dom
SElinux Security-Enhanced Linux 工具
一套强化Linux安全的MAC扩展模块 测试
美国国家安全局主导开发
SELinux的动做机制
集成Linux的动做机制
集成到Linux内核——2.6及以上
操做系统提供可定制的策略、管理工具
策略
SELINUXTYPE=targeted
仅保护最多见/关键的网络服务,其余不限制
主要软件包:selinux-policy、selinux-policy-targeted、libselinux-utils、libselinux-utils、conreutils、policycoreutils
SELINUXTYPE=mls
提供多层次、全面的安全防御策略
需扩展软件包:selinux-policy-mls、msctrans、policycoreutils-newrole
禁用/启用SELinux机制
方法一:修改kernel启动参数
添加selinux=0为禁用,改成1为启用
方法二:修改文件/etc/selinux/config
设置SELINUX=disabled以禁用
设置SELINUX=permissive宽松模式
设置SELINUX=enforcing强制模式
临时修改:setenforce
1是强制模式,0是宽松模式
修改SELinux
标签值至关于给文件加了一把锁。守护进程也有标签值,该值至关于钥匙,只有锁和钥匙匹配,才能打开文件,读取内容
修改文件标签值的方法
方法1:restorecon –Rv /path/to/dir
方法2:chconn –t 标签值 /path/to/dir
getsebool –a查看全部的布尔值
setsebool –P 布尔值 on 永久修改-P
安装setroubleshoot
yum –y install setroubleshoot*
重启后生效
有任何的selinux违规行为,系统都会给出提示和解决方案
若是是图形界面下,屏幕右上角会弹出消息 能够用sealert –b 查看
若是是字符终端下,能够查看/var/log/message
得到SELINUX设置帮助
#man ftpd_selinux
man httpd_selinux
man samba_selinux
有些服务,配置文件中也有说明
vim /etc/samba/smb.conf
实验测试
开启selinux
[root@localhost test]# grep -v ^# /etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted
临时开启
[root@localhost test]# getenforce 查看
Enforcing
[root@localhost test]# setenforce 1 开启 0为关闭
使用FTP服务进行测试
vim /etc/vsftpd/vsftpd
anonymous_enable=YES //开启匿名访问
write_enable=YES
anon_umask=022
anon_upload_enable=YES //容许上传文件
anon_mkdir_write_enable=YES
chown ftp /var/ftp/pub
service vsftpd start
客户端使用FTP登陆上去
put一个文件时,能够上传,但不能建立文件,全部上传失败
须要开启selinux布尔值
使用setsebool –P allow_ftp_anon_write=1
time setsebool –P allow_ftpd_full_access=1
[root@localhost test]# getsebool -a |grep allow_ftpd
allow_ftpd_anon_write --> on
allow_ftpd_full_access --> on
改完后能够上传文件了
若setsebool allow_ftpd_full_access=0时
关闭时
如何从其余目录拷贝的文件,没法去下载或上传,有继承关系
加密与解密
信息传递中的风险
加密
发送方:明文》》密文
接收方:密文》》明文
算法:加密/解密所使用的转换规则
密钥:加密/解密所使用的指令或代码
加密方式
单向加密:加密只能向一个方向进行。能够理解为输出明文数据,加密成乱码。不能将乱码反推回原始明文数据。可是原始的明文数据一致,生成的乱码也是同样的。经常使用的算法MD五、SHA。能够用于计算文件的完整性和保存加密密码。
对称加密: 使用相同的算法和密钥。对称密钥、共享密钥。
优势:加密效率高。缺点:密钥的传输和保管不方便。经常使用的算法有 des/3des/aes
非对称加密:公钥加密、私钥解密。
优势:密钥传输和保管方便。缺点加密效率低。经常使用算法RSA/DSA
/etc/shadow
$加密类型$随机数$密码+随机数加密后的值
保护信息的完整性
信息摘要:基于输入的信息生成长度较短、位数固定的散列值
对称加密
DES:Date Encryption Standard
AES:Advanced Encryption Standard
非对称加密
RSA:Rivest Shamirh Adleman
DSA:Digital Signature Algorithm
信息摘要
MD5:Message Digest Algorithm 5
SHA:Secure Hash Algorithm
MD5完整性校验
使用md5sum工具
从新生成MD5校验值
与软件官方提供的校验值比对
当文件内容同样,使用MD5校验也彻底同样
GnuPG加密工具
GnuPG:GNU Privacy Guard
最流行的数据加密、数据签名工具软件
使用GPG加/解密文件
对称方式
加密操做:--symmetric或-c
解密操做:--decrypt或-d
加密操做:gpg –a –c 文件名 (a是ascii码 –c加密)
解密操做:gpg 文件名
yum install –y pinentry-gtk
私钥签名:
# gpg -c file2
输出两次密码
在未解密的状况下,显示为乱码
gpg对称解密操做
#gpg –d file2.gpg >file2
输出相对应的密码,在查看file2文件
使用GPG非对称加密方式保护文件
gpg --gen-key
查看公钥环
查看私钥环
# gpg -a --export usera >/tmp/gpg.pub
导入GPG
解密gpg –d hehe.txt.gpg>hehe.txt
建立分离式数字签名
gpg -b 1.tar.gz
GPG验证
OpenSSL及证书服务
加密
解密
、
搭建自有的CA服务器,为颁发数字证书提供基础
[ CA_default ]
dir = /etc/pki/CA # Where everything is kept
certs = $dir/certs # Where the issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # database index file.
#unique_subject = no # Set to 'no' to allow creation of
# several ctificates with same subject.
new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate
serial = $dir/serial # The current serial number
crlnumber = $dir/crlnumber # the current crl number
# must be commented out to leave a V1 CRL
crl = $dir/crl.pem # The current CRL
private_key = $dir/private/ca.key # The private key
RANDFILE = $dir/private/.rand # private random number file
x509_extensions = usr_cert # The extentions to add to the cert
# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt = ca_default # Subject Name options
cert_opt = ca_default # Certificate field options
# Extension copying option: use with caution.
# copy_extensions = copy
..
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = CN
countryName_min = 2
countryName_max = 2
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = SH
localityName = Locality Name (eg, city)
localityName_default = SH
0.organizationName = Organization Name (eg, company)
0.organizationName_default = Default Company Ltd
..
默认CA配置目录位于/etc/pki/CA/,须要创建初初始化序列文件、索引文件
# cd /etc/pki/CA
[root@localhost CA]# touch index.txt
[root@localhost CA]# echo 01>serial
为CA服务器建立私钥,并设置一个私钥中令进行保护,设置权限为600
为CA服务器建立根证书