当前位置: 首页 > news >正文

Linux服务器系统安全

 Unit1
Tracking Security Updates
更新分以下三类
RHSA
RHBA
RHEA
yum updateinfo list    查看所有更新
yum updateinfo list --cve=CVE-2013-0755查看某一更新
yum --security list updates    查看安全更新
yum updateinfo list | grep 'Critical'|cut -f1 -d''|sort -u|wc -l

Unit2 
Managing Software Updates
rpm -qa >/root/pre-update-software.$(date +%Y%m%d)    把安装的所有的软件包导入到一个文件
yum updateinfo >/root/updateinfo-report.$(date +%Y%m%d)
yum update --security -y    只更新安全的包,安装前gpgcheck=1要开启
yum update --cve=    可以更新具体的
rpm --import     导入安装包的key
rpm -qa |grep gpg-pubkey    查看可信的GPG keys
rpm -qi gpg-pubkey    查看安装包的详细信息
rpm -K    rpm package    查看安装包的md5值是不是正确
rpm -vvK rpm package    给出调试信息
rpm -qp --scripts rpm package    查看安装包有没有脚本运行

Unit3
Creating File Systems 
lvcreate -l 100%FREE -n lvname vgname    -l, --extents LogicalExtentsNumber[%{VG|PVS|FREE|ORIGIN}]
cryptsetup luksFormat /dev/vgname/lvname    键入YES开始加密格式化,输入密码
cryptsetup luksOpen   /dev/vgname/lvname  luksname    打开并命名
mkfs -t ext4 /dev/mapper/luksname    设置文件系统
mkdir    /secret
mount    /dev/mapper/luksname    /secret
umout    /secret
cryptsetup luksClose luksname    关闭加密

dd if=/dev/urandom of=/path/to/passsword/file bs=4096 count=1    加密文件也可以用明文
chmod    600 /path/to/password/file
cryptsetup luksAddkey /dev/vdaN  /path/to/password/file        这里也需要输入密码
touch /etc/crypttab
luksname  /dev/vgname/lvname     /path/to/password/file
在/etc/fstab添加如下
/dev/mapper/luksname    /secret     ext4  defaults 1 2    这样就可以开机自动挂载加密分区了

Unit4
Managing File Systems
nosuid,noexec    命令没有suid权限和执行权限
tune2fs -l /dev/vd1 |head -n 19
tune2fs -l /dev/vda1 |grep 'mount options'
tune2fs -o user_xattr,acl /dev/vda1    给分区添加acl权限,也可以修改/etc/fstab文件
lsattr    查看文件特殊属性
chattr    +、-    语法
a    只能追加
i    禁止修改

Unit5
Managing Special Permissions
suid    setUID
guid    setGID
chmod u+s /path/to/procedure    所有人对程序有运行权限
chmod g+s /path/to/dir   文件夹下生成的文件的所属组不变
find /bin -perm /7000  查找/bin下所有特殊权限位
find /bin -perm  4000  精确查找
find /bin -perm -4000  setUID
find /bin -perm -2000  setGID
find /bin -perm -6000  setUID and setGID 还可以用/6000

Unit6
Managing Additional File Access Controls
umask    查看umask值
getfacl somefile    查看文件ACLs(access control lists)
setfacl -m u:bob:rwx /path/to/file    bob拥有所属者和所属组权限
setfacl -m d:u:smith:rx subdir    d默认u用户rx权限subdir子目录
setfacl -m o::r /pat/to/file    所有人可读

Unit7
Monitoring For File System Changes
AIDE (Advanced Intrusion Detection Environment)高级入侵检测环境
它的主要功能是检测文档的完整性
yum install -y aide    使用aide监控文件的权限
grep PERMS /etc/aide.conf    添加要监控的文件
PERMS = p+i+u+g+acl+selinux    p权限,inode,u用户,g用户组
/etc    PERMS
/root/\..* PERMS
aide --init        初始化数据库
mv /var/lib/aide/aide.db.new.gz /var/aide/aide.db.gz
aide --check    对上文文件进行更改,check核实

Unit8
Managing User Accounts
chage -m 0 -M 90 -W 7 -I 14  username
-m min days
-M max days
-W warn days
-I inactive days
chage -d 0 username 用户下次登录要修改密码
chage -l username  列出用户配置信息
userdel -r username    删除用户时同时删除目录
grep PASS_M /etc/login.defs 可以在配置文件里修改, 对新添加用户生效
#       PASS_MAX_DAYS   Maximum number of days a password may be used.
#       PASS_MIN_DAYS   Minimum number of days allowed between password changes.
#       PASS_MIN_LEN    Minimum acceptable password length.
PASS_MAX_DAYS   30
PASS_MIN_DAYS   3
PASS_MIN_LEN    8
getent passwd |cut -d: -f3 |sort -n |uniq -d 看看系统中有没有重复的账号

Unit9
Managing Pluggable Authentication Modules
PAM    可插拔的认证模块,可以按需要动态的对验证的内容进行变更,所以可以大大提高验证的灵活性
1、认证管理(authentication management)
接受用户名和密码,进而对该用户的密码进行认证,并负责设置用户的一些秘密信息
2、帐户管理(account management)
检查帐户是否被允许登录系统,帐号是否已经过期,帐号的登录是否有时间段的限制等等
3、密码管理(password management)
主要是用来修改用户的密码
4、会话管理(session management)
主要是提供对会话的管理和记账(accounting)
inux各个发行版中,PAM使用的验证模块一般存放在/lib/security/目录下,可以使用ls命令进行查看本计算机支持哪些

验证控制方式,一般的PAM模块名字例如pam_unix.so,模块可以随时在这个目录下添加和删除,这不会直接影响程序运

行,具体的影响在PAM的配置目录下。
PAM的配置文件一般存放在/etc/pam.d/目录下。
查看某个程序是否支持PAM,使用命令:
ldd `which cmd` | grep libpam  //cmd就代表查看的程序名
如果包含libpam库,那么该程序就支持PAM验证。
ldd `which login` |grep libpam      
        libpam.so.0 => /lib64/libpam.so.0 (0x000000326d200000)
        libpam_misc.so.0 => /lib64/libpam_misc.so.0 (0x000000326b600000)
/etc/pam.d Configuration File Syntax
type control module [module arguments]

grep maxlogins /etc/security/limits.conf   
#                 
#        - maxlogins - max number of logins for this user
@student        -       maxlogins       4    配置用户同时最大登录次数
@qa        hard    cpu        1    配置cpu使用时间

限制用户密码错误输入次数
cat /etc/pam.d/system-auth    同样password-auth也要改
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        required      pam_tally2.so onerr=fail deny=3 unlock_time=180 3次错误禁止3分钟
auth        sufficient    pam_fprintd.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 1000 quiet_success
auth        required      pam_deny.so

account     required      pam_tally2.so    还要注意放置的位置
account     required      pam_unix.so

pam_tally2    查看用户
pam_tally2 --reset -u username    重置释放禁用用户

Unit10
Securing Console Access
加密方式不一样$6 sh256  $1 md5
grub-crypt 
Password: 
Retype password: 
$6$01wSV5m9GBdGdQ3J

$oroEE6jjedQ59yQqJlxwAc1MBPSrdm6ufuUJil5rJaXmLgYNbsjz1F.kQlcrZYcrO5y9h014VkGCsH5PN7TTg.
grub-md5-crypt 
Password: 
Retype password: 
$1$HqxBl1$DVC9jyW6HXZ8.vAlPo2QR1
cat /etc/grub.cfg
password --encrypted $6$01wSV5m9GBdGdQ3J

$oroEE6jjedQ59yQqJlxwAc1MBPSrdm6ufuUJil5rJaXmLgYNbsjz1F.kQlcrZYcrO5y9h014VkGCsH5PN7TTg.
/etc/issue    认证前显示
/etc/motd  Message Of The Day and historically 认证后显示
/etc/ssh/sshd_config PermitRootLogin no 禁止root用户ssh登录

Unit11
Installing Central Authentication
IdM(Identity Management)
chkconfig NetworkManager off;service NetworkManager stop    关闭NetworkManager,否则ipa-server安装

不上
/etc/sysconfig/network-scripts/ifcfg-eth0    网卡配置静态IP,网关,DNS都要配置NM_CONTROLLED=no
/etc/hosts    本机的做解析   ip   server.example.com    server
yum -y install ipa-server 
ipa-server-install --idstart=2000 --idmax=20000  注意给uid加上一个区间
安装完成需要开启下列端口:
TCP Ports:
80,443  HTTP/HTTPS
389,636 LDAP/LDAPS
88,464    kerberos
UDP Ports:
88,464    kerberos
123    ntp
也可用命令行指定具体参数,这样就不需要在上面交互式指定
ipa-server-install --hostname=server.example.com -n example.com -r EXAMPLE.COM -p redhat123 -a 

redhat123 -U
service sshd restart
kinit admin        初始化,若是普通用户第一次要修改密码
ipa user-find admin    验证
剩下的添加用户,添加组,修改配置信息都可以在浏览器上操作https://server.example.com 登陆名admin 密码

redaht123
客户端安装如下:
yum -y install ipa-client
ipa-client-install --mkhomedir 注意要给新用户生成目录
安装的过程中要用admin redhat123认证一下
也可以用非交互式安装
ipa-client-install --domain=example.com --server=server.example.com --realm=EXAMPLE.COM -p admin -w 

redhat123 --mkhomedir -U
最后idm上的用户就可以在client上登陆了,登陆后自动生成家目录


Unit12
Managing Central Authentication
kinit admin
ipa pwpolicy-show 命令行查看策略
kpasswd bob  为用户修改密码
这些都可以在浏览器上操作,包括sudoers,用户能使用的命令等

Unit13
Configuring System Logging
ryslog-gnutls安装后支持TLS port 6514
日志服务器分为服务端和客户端
服务端配置如下:
/etc/rsyslog.conf    打开端口模块,支持TCP和UDP这里打开的是TCP
# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
/etc/rsyslog.d/remote.conf    这个文件是在rsyslog.d目录下新建的
:fromhost,isequal,"client.example.com" /var/log/client/messages
:fromhost,isequal,"client.example.com" ~    添加~后客户端的信息只保存在上面的文件中
客户端配置如下:
/etc/rsyslog.conf 先注释所有日志发送端口,本地不保留
*.* @@(o)server.example.com:514        两个@是走TCP(o)是为后面的端口号用
logrotate日志分割工具
其实还有个logwatch工具,可以把服务器重要信息每天发送给指定邮箱

Unit14
Configuring System Auditing
/etc/sysconfig/auditd
/etc/audit/auditd.conf    默认端口号tcp 60
/etc/audit/audit.rules    man rules查看语法
remote logging with auditd  /etc/audisp/plugins.d/syslog.conf  setting active=yes 后并重启auditd服务

可以用syslog发送信息到远程服务器
安装audispd-plugins包后(每个客户端,这是多节点),可以开启/etc/audisp/plugins.d/au-remote.conf 

active=yes把审核日志发送到日志服务器
具体语法可以man auditctl
/etc/audit/audit.rules
-w  /path/to/file -p rwxa -k key
-e 2
-w 指定审核文件路径
-p 访问权限  r读w写x执行a属性改变
-k key
-e 设置enabled flag,可以是0,1,2 设置2后/etc下其他文件就不要加进来,有问题得重启

Unit15
Controlling Access to Network Services
iptables 防火墙
iptables -L
iptables -F
iptables -X
iptables -Z
iptables -A INPUT -i lo -j ACCEPT    系统服务用
iptables -A INPUT -m state --stat ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 22 -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 514 -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -j LOG
iptables -A INPUT -j REJECT
server iptables save    保存记录
cat /etc/sysconfig/iptables    默认保存位置
iptables -nvL --line-numbers    查看核查
另外一个比较有用的地方,用于PPTP服务器,拨号进入后上网问题-s网段是PPTP服务器自动分配的IP
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE 

转载于:https://www.cnblogs.com/qyy349609115/p/9066842.html

相关文章:

  • 分布式之数据库和缓存双写一致性方案解析
  • 【NOIP2008】【Vijos1493】传纸条
  • Mac 如何安装 chromedriver
  • UPC-2249 曲线分割【递推】
  • postman接口测试:登录
  • Flannel - 原理
  • cpp
  • JS基础:常用API
  • LeetCode——18. 4Sum
  • resetlogs报错 ORA-00392
  • iOS项目中group和folder的区别
  • nginx资源争夺问题
  • 2018 ISCC Writeup
  • HololensAR开发设置
  • hdu1693 Eat the Trees 插头dp
  • 4月23日世界读书日 网络营销论坛推荐《正在爆发的营销革命》
  • GitUp, 你不可错过的秀外慧中的git工具
  • HTTP请求重发
  • HTTP中的ETag在移动客户端的应用
  • iOS高仿微信项目、阴影圆角渐变色效果、卡片动画、波浪动画、路由框架等源码...
  • js数组之filter
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • Promise面试题2实现异步串行执行
  • Python爬虫--- 1.3 BS4库的解析器
  • 后端_MYSQL
  • 基于阿里云移动推送的移动应用推送模式最佳实践
  • 简单实现一个textarea自适应高度
  • 开放才能进步!Angular和Wijmo一起走过的日子
  • 前端技术周刊 2018-12-10:前端自动化测试
  • 数组大概知多少
  • 算法-插入排序
  • 吐槽Javascript系列二:数组中的splice和slice方法
  • 译米田引理
  • RDS-Mysql 物理备份恢复到本地数据库上
  • ​【原创】基于SSM的酒店预约管理系统(酒店管理系统毕业设计)
  • ​批处理文件中的errorlevel用法
  • ​人工智能之父图灵诞辰纪念日,一起来看最受读者欢迎的AI技术好书
  • # Java NIO(一)FileChannel
  • #stm32驱动外设模块总结w5500模块
  • $.proxy和$.extend
  • ( 10 )MySQL中的外键
  • (8)Linux使用C语言读取proc/stat等cpu使用数据
  • (done) NLP “bag-of-words“ 方法 (带有二元分类和多元分类两个例子)词袋模型、BoW
  • (附源码)ssm捐赠救助系统 毕业设计 060945
  • (附源码)ssm考试题库管理系统 毕业设计 069043
  • (附源码)计算机毕业设计ssm基于Internet快递柜管理系统
  • (蓝桥杯每日一题)平方末尾及补充(常用的字符串函数功能)
  • .NET : 在VS2008中计算代码度量值
  • .net core 源码_ASP.NET Core之Identity源码学习
  • .NET 编写一个可以异步等待循环中任何一个部分的 Awaiter
  • .NET平台开源项目速览(15)文档数据库RavenDB-介绍与初体验
  • .NET中 MVC 工厂模式浅析
  • 。Net下Windows服务程序开发疑惑
  • @Autowired和@Resource的区别
  • @property括号内属性讲解