日期:2014-05-16  浏览次数:20655 次

Linux安全设置


******************************************************************************
1.关闭不必要的服务
yum -y install ntsysv
ntsysv
# 关闭不需要的服务按上面的安装关闭 ip6tables、jexec、kudzu、lvm2-monitor、mcstrans、netfs、rawdevices、restorecond

2.禁止Ctrl+Alt+Delete重新启动机器命令
vi /etc/inittab
注释掉: ca::ctrlaltdel:/sbin/shutdown -t3 -r now
设置/etc/rc.d/init.d/下权限
chmod -R 700 /etc/rc.d/init.d/*

?

3.限制su的使用,设置仅wheel用户使用
vi /etc/pam.d/su
取消下面行注释
> auth??????????? required??????? pam_wheel.so use_uid
echo "SU_WHEEL_ONLY yes" >> /etc/login.defs 

4.阻止ping(慎用)
# vi /etc/rc.d/rc.local
添加到文件末尾
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

5.防止ip欺骗
vi /etc/host.conf
添加下面几行
order bind,hosts
multi off
nospoof on

6.防止DoS攻击
对系统所有的用户设置资源限制可以防止DoS类型攻击,如最大进程数和内存使用数量等。
例如,可以在/etc/security/limits.conf中添加如下几行:
vi /etc/security/limits.conf
*hard core 0
*hard rss 5000
*hard nproc 50
然后必须编辑/etc/pam.d/login文件检查下面一行是否存在。
cat /etc/pam.d/login
# echo "sessionrequired/lib/security/pam_limits.so" >> /etc/pam.d/login
sessionrequired/lib/security/pam_limits.so
上面的命令禁止调试文件,限制进程数为50并且限制内存使用为5MB。

7.禁止ipv6
vi /etc/modprobe.conf
alias net-pf-10 off
alias ipv6 off

8.删除不必要的用户和组
userdel adm
userdel sync
userdel shutdown
userdel halt
userdel news
userdel uucp
userdel operator
userdel games
userdel gopher
userdel ftp

groupdel news
groupdel uucp
groupdel dip

9。更改SSH端口,不允许使用低版本的SSH协议,创建远程登录用户,禁止root登录
#vi /etc/ssh/sshd_config
将PORT改为1000以上端口
将#protocol 2,1改为protocol 2
禁止root登录,修改如下
PermitRootLogin no
例如
PORT 1984
Protocol 2
PermitRootLogin no
# 添加新端口到iptables中
vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1984 -j ACCEPT

##注意这里必须添加远程登录用户,并添加到wheel用户组
-----------------------------------
useradd [-G wheel] yubaojian0616
passwd yubaojian0616
usermod -g wheel yubaojian0616
-----------------------------------

X.修改口令文件属性
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow

?

X+1.定时校正服务器时钟,定时与中国国家授时中心授时服务器同步
crontab -e

* * * * * * ntpdate 210.72.145.44