CentOS 6服务器简单安全配置
生活随笔
收集整理的這篇文章主要介紹了
CentOS 6服务器简单安全配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 禁用不使用的用戶
-
cp /etc/passwd{,.bak}修改之前先備份
-
vi /etc/passwd編輯用戶,在前面加上#注釋掉此行
2. 關閉不使用的服務
#?chkconfig?--list?|grep?'3:on' 通用unix打印服務,對服務器無用:```shell service?cups?stop chkconfig?cups?--level?2345?off service?cpuspeed?stop chkconfig?cpuspeed?--level?2345?off service?bluetooth?stop chkconfig?bluetooth?--level?2345?off service?firstboot?stop chkconfig?firstboot?--level?2345?off service?netfs?stop chkconfig?netfs?--level?2345?off service?nfslock?stop chkconfig?nfslock?--level?2345?off service?acpid?start?&&?chkconfig?acpid?on3. 禁用IPV6
禁止加載IPv6模塊
alias?net-pf-10?off options?ipv6?disable=1 #?vi?/etc/sysconfig/network NETWORKING_IPV6=no #?vi?/etc/sysconfig/network-scripts/ifcfg-eth0 IPV6INIT=no IPV6_AUTOCONF=no #?chkconfig?ip6tables?off #?lsmod?|?grep?ipv6 #?ifconfig?|?grep?-i?inet64. iptables規則
5. SSH安全設置
#?useradd?crm?-d?/apps/crm #?passwd?crm#?useradd?sysmgr #?passwd?sysmgr5.1 只允許wheel用戶組的用戶su切換
#?usermod?-G?wheel?sysmgr#?vi?/etc/pam.d/su #?Uncomment?the?following?line?to?require?a?user?to?be?in?the?"wheel"?group. auth????????????required????????pam_wheel.so?use_uid5.2 登錄超時
export?TMOUT=300 readonly?TMOUT5.3 禁止root直接遠程登錄
#?vi?/etc/ssh/sshd_config PermitRootLogin?no5.4 限制登錄失敗次數并鎖定
auth?required?pam_tally2.so?deny=6?unlock_time=180?even_deny_root?root_unlock_time=1805.5 登錄IP限制
##?allowed?ssh?users?sysmgr AllowUsers?sysmgr@172.29.73.* vi?/etc/hosts.deny sshd:all vi?/etc/hosts.allow sshd:172.29.73.23 sshd:172.29.73.6. 配置只能使用密鑰文件登錄
[dir@username?~]$?ssh-keygen?-t?rsa?-b?2048 Generating?public/private?rsa?key?pair. Enter?file?in?which?to?save?the?key?(/root/.ssh/id_rsa):???//默認路徑,回車 Enter?passphrase?(empty?for?no?passphrase):?????//輸入你的密鑰短語,登錄時使用 Enter?same?passphrase?again:? Your?identification?has?been?saved?in?/root/.ssh/id_rsa. Your?public?key?has?been?saved?in?/root/.ssh/id_rsa.pub. The?key?fingerprint?is: 3e:fd:fc:e5:d3:22:86:8e:2c:4b:a7:3d:92:18:9f:64?root@ibpak.tp-link.net The?key's?randomart?image?is: +--[?RSA?2048]----+ |?????????????????| … |??????o++o..oo..o| +-----------------+ $?mv?~/.ssh/id_rsa.pub?~/.ssh/authorized_keys $?chmod?600?~/.ssh/authorized_keys RSAAuthentication?yes PubkeyAuthentication?yes AuthorizedKeysFile??????.ssh/authorized_keys Match?User?itsectionPasswordAuthentication?no7. 減少history命令記錄
vi?/etc/profile8. 增強特殊文件權限
chattr?+i?/etc/passwd chattr?+i?/etc/shadow chattr?+i?/etc/group chattr?+i?/etc/gshadow chattr?+i?/etc/services?#給系統服務端口列表文件加鎖,防止未經許可的刪除或添加服務 chattr?+i?/etc/pam.d/su chattr?+i?/etc/ssh/sshd_config lsattr?/etc/passwd?/etc/shadow?/etc/services?/etc/ssh/sshd_config9. 防止一般網絡攻擊
9.1 禁ping
#?echo?1?>?/proc/sys/net/ipv4/icmp_echo_ignore_all iptables?-A?INPUT?-p?icmp?--icmp-type?0?-s?0/0?-j?DROP iptables?-A?OUTPUT?-p?icmp?--icmp-type?8?-j?DROP9.2. 防止IP欺騙
order?hosts,bind????#名稱解釋順序 multi?on???????????#允許主機擁有多個IP地址 nospoof?on?????????#禁止IP地址欺騙9.3 防止DoS攻擊
*????soft????core????0 *????soft????nproc???2048 *????hard????nproc???16384 *????soft????nofile?1024 *????hard????nofile??65536-
core 0表示禁止創建core文件
-
nproc 128把最多的進程數限制到20
-
nofile 64表示把一個用戶同時打開的最大文件數限制為64
-
*表示登錄到系統的所有用戶,不包括root
10. 修復已知安全漏洞
11. 定期做日志安全檢查
-
/var/log/message– 記錄系統日志或當前活動日志
-
/var/log/auth.log– 身份認證日志
-
/var/log/cron– Crond 日志 (cron 任務)
-
/var/log/maillog– 郵件服務器日志
-
/var/log/secure– 認證日志
-
/var/log/wtmp歷史登錄、注銷、啟動、停機日志和,lastb命令可以查看登錄失敗的用戶
-
/var/run/utmp當前登錄的用戶信息日志,w、who命令的信息便來源與此
-
/var/log/yum.logYum 日志
11.1 安裝logwatch
總結
以上是生活随笔為你收集整理的CentOS 6服务器简单安全配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第五届省赛(软件类)真题----Java
- 下一篇: 原型设计列表