RH413-RHEL6.4課程總結
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=<CVE> 可以更新具體的
rpm --import <GPG-KEY-FILE> 導入安裝包的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
#<domain> <type> <item> <value>
# - 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
RH413-RHEL6.4課程總結
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.