linux服务器基本安全配置手册(3)
时间:2010-09-03 来源:mydear
11.关闭系统不使用的服务:
cd /etc/init.d #进入到系统init进程启动目录
在这里有两个方法,可以关闭init目录下的服务,
一、将init目录下的文件名mv成*.old类的文件名,即修改文件名,作用就是在系统启动的时候找不到这个服务的启动文件。
二、使用chkconfig系统命令来关闭系统启动等级的服务。
注:在使用以下任何一种方法时,请先检查需要关闭的服务是否是本服务器特别需要启动支持的服务,以防关闭正常使用的服务。
使用chkcofig命令来关闭不使用的系统服务 (level前面为2个减号)要想在修改启动脚本前了解有多少服务正在运行,输入:
ps aux | wc -l
然后修改启动脚本后,重启系统,再次输入上面的命令,就可计算出减少了多少项服务。越少服务在运行,安全性就越好。另外运行以下命令可以了解还有多少服务在运行:
netstat -na --ip
批量方式先停止服务
for i in acpid anacron apmd atd auditd autofs avahi-daemon avahi-dnsconfd bluetooth cpuspeed cups dhcpd firstboot gpm haldaemon hidd ip6tables ipsec isdn kudzu lpd mcstrans messagebus microcode_ctl netfs nfs nfslock nscd pcscd portmap readahead_early restorecond rpcgssd rpcidmapd rstatd sendmai
l setroubleshoot snmpd sysstat xfs xinetd yppasswdd ypserv yum-updatesd ;do service $i stop;done
关闭启动服务
for i in acpid anacron apmd atd auditd autofs avahi-daemon avahi-dnsconfd bluetooth cpuspeed cups dhcpd firstboot gpm haldaemon hidd ip6tables ipsec isdn kudzu lpd mcstrans messagebus microcode_ctl netfs nfs nfslock nscd pcscd portmap readahead_early restorecond rpcgssd rpcidmapd rstatd sendmai
l setroubleshoot snmpd sysstat xfs xinetd yppasswdd ypserv yum-updatesd ;do chkconfig $i off;done
以下为手动方式及解释,执行批量方式后不需再执行了
chkconfig --level 345 apmd off ##笔记本需要
chkconfig --level 345 netfs off ## nfs客户端
chkconfig --level 345 yppasswdd off ## NIS服务器,此服务漏洞很多
chkconfig --level 345 ypserv off ## NIS服务器,此服务漏洞很多
chkconfig --level 345 dhcpd off ## dhcp服务
chkconfig --level 345 portmap off ##运行rpc(111端口)服务必需
chkconfig --level 345 lpd off ##打印服务
chkconfig --level 345 nfs off ## NFS服务器,漏洞极多
chkconfig --level 345 sendmail off ##邮件服务, 漏洞极多
chkconfig --level 345 snmpd off ## SNMP,远程用户能从中获得许多系统信息
chkconfig --level 345 rstatd off ##避免运行r服务,远程用户可以从中获取很多信息
chkconfig --level 345 atd off ##和cron很相似的定时运行程序的服务
注:以上chkcofig 命令中的3和5是系统启动的类型,以下为数字代表意思
0:开机(请不要切换到此等级)
1:单人使用者模式的文字界面
2:多人使用者模式的文字界面,不具有网络档案系统(NFS)功能
3:多人使用者模式的文字界面,具有网络档案系统(NFS)功能
4:某些发行版的linux使用此等级进入x windows system
5:某些发行版的linux使用此等级进入x windows system
6:重新启动
如果不指定--level 单用on和off开关,系统默认只对运行级3,4,5有效
chkconfig cups off #打印机
chkconfig bluetooth off # 蓝牙
chkconfig hidd off # 蓝牙
chkconfig ip6tables off # ipv6
chkconfig ipsec off # vpn
chkconfig auditd off #用户空间监控程序
chkconfig autofs off #光盘软盘硬盘等自动加载服务
chkconfig avahi-daemon off #主要用于Zero Configuration Networking ,一般没什么用建议关闭
chkconfig avahi-dnsconfd off #主要用于Zero Configuration Networking ,同上,建议关闭
chkconfig cpuspeed off #动态调整CPU频率的进程,在服务器系统中这个进程建议关闭
chkconfig isdn off #isdn
chkconfig kudzu off #硬件自动监测服务
chkconfig nfslock off #NFS文档锁定功能。文档共享支持,无需的能够关了
chkconfig nscd off #负责密码和组的查询,在有NIS服务时需要
chkconfig pcscd off #智能卡支持,,如果没有可以关了
chkconfig yum-updatesd off #yum更新
chkconfig acpid off
chkconfig autofs off
chkconfig firstboot off
chkconfig mcstrans off #selinux
chkconfig microcode_ctl off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig setroubleshoot off
chkconfig xfs off
chkconfig xinetd off
chkconfig messagebus off
chkconfig gpm off #鼠标
chkconfig restorecond off #selinux
chkconfig haldaemon off
chkconfig sysstat off
chkconfig readahead_early off
chkconfig anacron off
需要保留的服务
crond , irqbalance , microcode_ctl ,network , sshd ,syslog
因为有些服务已运行,所以设置完后需重启
chkconfig
/*
语法:chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]
补充说明:这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。
参数:
--add 增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。
--del 删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。
--level<等级代号> 指定读系统服务要在哪一个执行等级中开启或关毕
*/