Linux系统安全详解


一,BIOS安全(硬件上的安全) 1,最基本最简单的安全配置,保障计算机硬件配置等不被别人更改.给BIOS设置密码,防止改变启动顺序从软盘或光盘启动.防止特殊的启动盘启动用户的系统,进入rescue或其他模式.改变或删除当前配置等.每一个细心的网管每个细节都不应该忽视! 2,禁止使用contral+alt+delete重起机器 编辑/etc/inittab文件,注释掉下面一行. ca::ctrlaltdel:/sbin/shutdown -t3 -r now 该成:(使用# # ca::ctrlaltdel:/sbin/shutdown -t3 -r now   二,帐号安全 口令,系统的第一道防线,目前大多数数攻击都是截获口令或猜测口令等口令攻击开始的. /etc 目录下主要存放系统的配置文件.我们要对这个目录下的好多文件进行修改. 1,/etc/login.defs文件是login程序的配置文件.口令的长度和口令的有效期等可以在这里设置. [root@tp ~]# vi /etc/login.defs
...
PASS_MAX_DAYS   9999  密码被用最多天数
PASS_MIN_DAYS   0     密码被用最少天数
PASS_MIN_LEN    5     系统默认密码长度5,我们可以该成8或更多.
PASS_WARN_AGE   7     密码有效期警告,超过7天将提示用户更换新的密码.
...
  2,/etc/profile文件是环境变量设置文件.在此文件设置环境变量将对所有用户生效.我们要在此文件设置自动注销帐户的时间.及命令的历史记录数. [root@tp ~]# vi /etc/profile
...
HOSTNAME=`/bin/hostname`
HISTSIZE=1000 这里1000代表用户操作命令的历史记录.应尽量小一些.设置成0也可以,呵呵.
tmout=600 添加此行,如果系统用户在600秒(10分钟)内不做任何操作,将自动注销这个用户.
... 3,/etc/passwd文件存放系统用户名,用户标识(UID),组标识(GID)等的地方.我们要在这里找到并清除没有设置口令的用户.同时还要清除一些特别帐号(因为可能会存在潜在的危险). [root@tp ~]# vi /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
...
wh::500:501::/home/wh:/bin/bash
仔细观察上面的一行(wh用户),在第二项,两个冒号中间什么都没有,而上面的的用户(如root用户)都是x. 这表明此用户没有密码.要不添加上,要不删掉. 4,特别帐号的处理 如果不启动用sendmail,删除如下用户 [root@tp wh]# userdel adm [root@tp wh]# userdel lp [root@tp wh]# userdel sync
[root@tp wh]# userdel shudown
[root@tp wh]# userdel halt
[root@tp wh]# userdel mail
如果不用X windows服务器.可有删除
[root@tp wh]# userdel news
[root@tp wh]# userdel uucp
[root@tp wh]# userdel operator
[root@tp wh]# userdel games
如果不允许匿名FTP帐号登陆,可删除
[root@tp wh]# userdel gopher
[root@tp wh]# userdel ftp
  三,重要文件的安全设置. 首先要了解两个命令 1,chmod:改变文件的属主 2,chattr:改变文件属性 我们要做的是把重要文件的属主改成root并给相应的权限,还有就是改变文件的属性让它禁止被修改 我们来统计一下重要文件:(其实,只要你不想让其他用户更改的文件都可以这么做,我这里只是为安全而选择了下面的文件.) 1,/etc/passwd,passwd-,passwd.OLD,group,group- 用户,组的ID等信息文件. 2,/etc/shadow,shadow-,gshadow,gshadow- 用户,组密码加密文件. 3,/etc/xinetd.conf 网络守护进程主配置文件 4,/etc/inittab  系统在启动是会读取这个文件里的内容. 5,/etc/services 防止未经许可的删除或添加服务 6,/etc/rc.d/rc.sysinit 系统启动是需要读取的文件, 7,/etc/rc.d/init.d/*   以一个文件为例,其它都一样 [root@tp etc]# chmod 700 passwd
[root@tp etc]# chattr +i passwd
当chattr +i时就是禁止对文件进行修改,当我们要添加用户时,就会有麻烦,因为passwd文件禁止修改写入.所以我们还要该掉它的属性.chattr -i.   四,防止攻击系统安全设置 1,限制用户使用系统资源,主要包括资源最大进程数,内存使用量等.这样可以防止DOS类型攻击. 需要编辑文件 [root@tp /]# vi /etc/security/limits.conf ... (这三行是添加的) * hard core 0    禁止创建core文件 
* hard rss 5000  其他用户(除root)最多使用5M内存
* hard nproc 20  最多进程数限制在20
注:*表示所有登陆到linux的用户.
# End of file [root@tp /]# vi /etc/pam.d/login
...
在文件末尾加入下面一行 session required /lib/security/pam_limits.so 2,限制控制台的访问 [root@tp /]# vi /etc/securetty ... 我们注释掉
tty1
# tty2
# tty3
# tty4
# tty5
# tty6
只留下tty1,这时,root仅可在tty1终端登录 3,禁止外来ping请求. [root@tp /]# vi /etc/rc.d/rc.local ...
在最后加入一行
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all 4,防止IP地址欺骗 [root@tp /]# vi /etc/host.conf 加入如下几行 order bind,hosts
multi off
nospoof on
5,禁止su命令进入root(这一部我反复测试总是不成功,group组里的用户依然不能su成root用户.希望知道的朋友告诉我,谢谢) [root@tp pam.d]# vi /etc/pam.d/su ... 在下面加入如下两行 auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=xxx
这表示只有xxx组的用户可以su成root. 6,使用TCP_WRAPPER 在默认情况下linux系统允许所有请求,可用TCP_WRAPPER增强安全性, 在/etc/hosts.deny写入"ALL:ALL"禁止所有请求 [root@tp etc]# vi /etc/hosts.deny
#
# hosts.deny    This file describes the names of the hosts which are
#               *not* allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow.  In particular
# you should know that NFS uses portmap!
   "ALL:ALL" 把允许访问的客户,或服务添加到/etc/hosts.allow,冒号左边为服务,冒号右边为授权的机器 [root@tp etc]# vi /etc/hosts.allow
#
# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
vsftp:211.101.46.253    注:仅如许IP地址为211.101.46.253的机器访问FIP服务器
7.删减登录信息   [root@tp ~]# rm -f /etc/issue
  [root@tp ~]# rm -f /etc/issue.net
 [root@tp ~]# touch /etc/issue
  [root@tp ~]# touch /etc/issue.net
  • 1
  • 2
  • 下一页

相关内容