Linux安全清单

1.物理安全

确保每次本机登录服务器后的SignOut过程;设置BIOS密码且修改引导次序禁止从软盘启动系统;

2.使用安全密码

包括对密码长度和密码复杂度的相应要求;

3.限制不必要的用户数量

注意经常检查系统的账号,删除已经不再使用的账号,并注意检查相应账号的权限设置;

4. 口令文件

使用chattr命令给下面的文件加上不可更改属性,防止非授权用户获得权限:

# chattr +i /etc/passwd
# chattr +i /etc/shadow
# chattr +i /etc/group
# chattr +i /etc/gshadow

5. 禁止Ctrl+Alt+Delete重新启动机器命令

修改/etc/inittab文件,将”ca::ctrlaltdel:/sbin/shutdown -t3 -r now”一行注释掉,然后重新设置/etc/rc.d/init.d/目录下所有文件的许可权限:

# chmod -R 700 /etc/rc.d/init.d/*

6. 限制su命令

编辑/etc/pam.d/su文件,增加如下两行:

auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=isd

这时,仅isd组的用户可以用su作为root;

7. 删减登录信息

编辑/etc/rc.d/rc.local将输出系统信息的如下行通通注释掉:

# This will overwrite /etc/issue at every boot. So, make any changes you
# want to make to /etc/issue here or you will lose them when you reboot
# echo "" > /etc/issue
# echo "$R" >> /etc/issue
# echo "Kernel $(uname -r) on $a $(uname -m)" >> /etc/issue
# cp -f /etc/issue /etc/issue.net
# echo >> /etc/issue

然后,进行如下操作:

# rm -f /etc/issue
# rm -f /etc/issue.net
# touch /etc/issue
# touch /etc/issue.net

8.限制NFS访问 

应该确保你的/etc/exports具有最严格的访问权限设置,也就是意味着不要使用任何通配符、不允许root写权限并且只能安装为只读文件系统,编辑文件/etc/exports并加入如下两行。

/dir/to/export host1.mydomain.com(ro,root_squash)
/dir/to/export host2.mydomain.com(ro,root_squash)

/dir/to/export 是你想输出的目录,host.mydomain.com是登录这个目录的机器名,ro意味着mount成只读系统,root_squash禁止root写入该目录;

为了使改动生效,运行如下命令:

# /usr/sbin/exportfs –a

9.Inetd设置

首先要确认/etc/inetd.conf的所有者是root,且文件权限设置为600。设置完成后,可以使用”stat”命令进行检查;

# chmod 600 /etc/inetd.conf

然后,编辑/etc/inetd.conf禁止以下服务;

ftp telnet shell login exec talk ntalk imap pop-2 pop-3 finger auth

如果你安装了ssh/scp,也可以禁止掉Telnet/FTP;

为了使改变生效,运行如下命令:

#killall -HUP inetd

请使用TCP_WRAPPERS增强系统安全性,可以修改/etc/hosts.deny和/etc/hosts.allow来增加访问限制;

例如,将/etc/hosts.deny设为”ALL: ALL”可以默认拒绝所有访问;然后在/etc/hosts.allow文件中添加允许的访问;例如,”sshd: 192.168.1.10/255.255.255.0 gate.openarch.com”表示允许IP地址192.168.1.10和主机名gate.openarch.com允许通过SSH连接;

配置完成后,可以用tcpdchk检查:

# tcpdchk
(tcpchk是TCP_Wrapper配置检查工具,它检查你的tcp wrapper配置并报告所有发现的潜在/存在的问题);

10.登录终端设置

/etc/securetty文件指定了允许root登录的tty设备,由/bin/login程序读取,
其格式是一个被允许的名字列表,你可以编辑/etc/securetty且注释掉如下的行;

# tty1
# tty2
# tty3
# tty4
# tty5
# tty6

这时,root仅可在tty1终端登录;

11.避免显示系统和版本信息

可以如下改变/etc/inetd.conf文件:

telnet stream tcp nowait root /usr/sbin/tcpd in.telnetd -h

加-h表示telnet不显示系统信息,而仅仅显示”login:”;

12.阻止ping

在/etc/rc.d/rc.local文件中增加如下一行:

echo 1 >/proc/sys/net/ipv4/
icmp_echo_ignore_all

13.防止IP欺骗

编辑host.conf文件并增加如下几行:

order bind,hosts
multi off
nospoof on

14.防止DoS攻击

对系统所有的用户设置资源限制可以防止DoS类型攻击,如最大进程数和内存使用数量等;例如,可以在/etc/security/limits.conf中添加如下几行:

* hard core 0
* hard rss 5000
* hard nproc 20

然后必须编辑/etc/pam.d/login文件检查下面一行是否存在。

session required /lib/security/pam_limits.so

上面的命令禁止调试文件,限制进程数为50并且限制内存使用为5MB。

15.安装补丁

经常访问相应系统网站和一些安全站点,下载最新的漏洞补丁;

具体网址:

REDHAT
ftp://updates.redhat.com/

DEBIAN
http://www.debian.org/security/
或者使用apt-get update/upgrade 进行相应的升级工作;

source.list如下:
deb http://security.debian.org/ slink updates
或 deb http://security.debian.org/ potato/updates main contrib non-free