Chinaunix首页 | 论坛 | 博客
  • 博客访问: 335324
  • 博文数量: 64
  • 博客积分: 2301
  • 博客等级: 大尉
  • 技术积分: 570
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 11:48
文章分类

全部博文(64)

文章存档

2013年(5)

2012年(6)

2011年(36)

2010年(7)

2009年(10)

分类: LINUX

2011-06-01 01:37:40

st1\:*{behavior:url(#ieooui) }

Linux安全配置步骤简述

一、磁盘分区

◆1、如果是新安装系统,对磁盘分区应考虑安全性:

1)根目录(/)、用户目录(/home)、临时目录(/tmp)和/var目录应分开到不同的磁盘分区;

2)以上各目录所在分区的磁盘空间大小应充分考虑,避免因某些原因造成分区空间用完而导致系统崩溃;

◆2、对于/tmp/var目录所在分区,大多数情况下不需要有suid属性的程序,所以应为这些分区添加nosuid属性;

方法一:修改/etc/fstab文件,添加nosuid属性字。例如:

/dev/hda2       /tmp      ext2     exec,dev,nosuid,rw      0 0

方法二:如果对/etc/fstab文件操作不熟,建议通过linuxconf程序来修改。

* 运行linuxconf程序;

* 选择"File systems"下的"Access local drive"

* 选择需要修改属性的磁盘分区;

* 选择"No setuid programs allowed"选项;

* 根据需要选择其它可选项;

* 正常退出。(一般会提示重新mount该分区)

二、安装

1、对于非测试主机,不应安装过多的软件包。这样可以降低因软件包而导致出现安全漏洞的可能性。

2、对于非测试主机,在选择主机启动服务时不选择非必需的服务。例如routedypbind等。

三、安全配置与增强

内核升级。起码要升级至2.2.16以上版本。

GNU libc共享库升级。(警告:如果没有经验,不可轻易尝试。可暂缓。)

关闭危险的网络服务。echochargenshellloginfingerNFSRPC

关闭非必需的网络服务。talkntalkpop-2

常见网络服务安全配置与升级

确保网络服务所使用版本为当前最新和最安全的版本。

取消匿名FTP访问

去除非必需的suid程序

使用tcpwrapper

使用ipchains防火墙

日志系统syslogd

一些细节:

◆1、操作系统内部的log file是检测是否有网络入侵的重要线索,当然这个假定你的logfile不被侵入者所破坏,如果你有台服务器用专线直接连到Internet上,这意味 着你的IP地址是永久固定的地址,你会发现有很多人对你的系统做telnet/ftp登录尝试,试着运行如下语句去检查。

#more /var/log/secure | grep refused

◆2、限制具有SUID权限标志的程序数量,具有该权限标志的程序以root身份运行,是一个潜在的安全漏洞,当然,有些程序是必须要具有该标志的,象passwd程序。

◆3BIOS安全。设置BIOS密码且修改引导次序禁止从软盘启动系统。

◆4、用户口令。用户口令是Linux安全的一个最基本的起点,很多人使用的用户口令就是简单的password,这等于给侵入者敞开了大 门,虽然从理论上说没有不能确解的用户口令,只要有足够的时间和资源可以利用。比较好的用户口令是那些只有他自己能够容易记得并理解的一串字符,并且绝对 不要在任何地方写出来。

◆5/etc/exports 文件。如果你使用NFS网络文件系统服务,那么确保你的/etc/exports具有最严格的存取权限设置,不意味着不要使用任何通配符,不允许root 写权限,mount成只读文件系统。编辑文件/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

◆6、确信/etc/inetd.conf的所有者是root,且文件权限设置为600

 

编辑/etc/inetd.conf禁止以下服务:

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

auth, etc. 除非你真的想用它。

特别是禁止那些r命令.如果你用ssh/scp,那么你也可以禁止掉telnet/ftp

为了使改变生效,运行

#killall -HUP inetd

你也可以运行

#chattr i /etc/inetd.conf

使该文件具有不可更改属性。

只有root才能解开,用命令

#chattr -i /etc/inetd.conf

 

◆7 TCP_WRAPPERS

默认地,Redhat Linux允许所有的请求,TCP_WRAPPERS增强你的站点的安全性是举手

之劳,你可以放入

“ALL: ALL”/etc/hosts.deny中禁止所有的请求,然后放那些明确允许的请求到

/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检查

[root@deep]# tcpdchk

tcpchkTCP_Wrapper配置检查工具,

它检查你的tcp wrapper配置并报告所有发现的潜在/存在的问题。

◆8、别名文件 aliases

编辑别名文件/etc/aliases(也可能是/etc/mail/aliases),移走/注释掉下面的行。

# Basic system aliases -- these MUST be present.

MAILER-DAEMON: postmaster

postmaster: root

# General redirections for pseudo accounts.

bin: root

daemon: root

#games: root ?remove or comment out.

#ingres: root ?remove or comment out.

nobody: root

#system: root ?remove or comment out.

#toor: root ?remove or comment out.

#uucp: root ?remove or comment out.

# Well-known aliases.

#manager: root ?remove or comment out.

#dumper: root ?remove or comment out.

#operator: root ?remove or comment out.

# trap decode to catch security attacks

#decode: root

# Person who should get root's mail

#root: marc

最后更新后不要忘记运行/usr/bin/newaliases,使改变生效。

◆9sysctl的修改

echo "

 

#improve the number of open files

fs.file-max = 60000

 

#disable ip source routing

net.ipv4.conf.all.accept_source_route = 0

net.ipv4.conf.lo.accept_source_route = 0

net.ipv4.conf.eth0.accept_source_route = 0

net.ipv4.conf.default.accept_source_route = 0

 

#enable ignoring broadcasts request

net.ipv4.icmp_echo_ignore_broadcasts = 1

 

#enable ignoring ping request

net.ipv4.icmp_echo_ignore_all = 1

 

 

#disbale icmp redirect acceptance

net.ipv4.conf.all.accept_redirects = 0

net.ipv4.conf.lo.accept_redirects = 0

net.ipv4.conf.lo.eth0.accept_redirects = 0

net.ipv4.conf.lo.default.accept_redirects = 0

 

# enable bad error message protection

net.ipv4.icmp_ignore_bogus_error_response = 1

 

#enable log spoofed packets.source routed packets,redirect packets

net.ipv4.conf.all.log_martians = 1

net.ipv4.conf.lo.log_martians = 1

net.ipv4.conf.eth0.log_martians = 1

net.ipv4.conf.default.log_martians = 1

 

#decrease the time default value for tcp_fin_timeout connection

net.ipv4.tcp_fin_timeout = 30

 

#decrease the time default value for tcp_keeplive_time connection

net.ipv4.tcp_keeplive_time = 1800

 

#turn off the tcp_window_scaling support

net.ipv4.tcp_window_scaling = 0

 

#turn off the tcp_sack support

net.ipv4.tcp_sack = 0

 

#turn off the tcp_timestamps support

net.ipv4.tcp_timestamps = 0

 

" >> /etc/sysctl.conf

◆10、不要显示出操作系统和版本信息。

如果你希望某个人远程登录到你的服务器时不要显示操作系统和版本信息,你能改变

/etc/inetd.conf中的一行象下面这样:

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

-h标志在最后使得telnet后台不要显示系统信息,而仅仅显示login:

◆11The /etc/host.conf file

编辑host.conf文件(vi /etc/host.conf)且加下面的行:

# Lookup names via DNS first then fall back to /etc/hosts.

order bind,hosts

# We don't have machines with multiple IP addresses on the same card

(like virtual server,IP Aliasing).

multi off

# Check for IP address spoofing.

nospoof on

IP Spoofing: IP-Spoofing is a security exploit that works by tricking

computers in a trust relationship that you are someone that you really aren't.

◆12. The /etc/securetty file and /etc/inittab file

该文件指定了允许root登录的tty设备,/etc/securetty/bin/login程序读取,它的

格式是一行一个被允许的名字列表,如你可以编辑/etc/securetty且注释出下面的行。

tty1

#tty2

#tty3

#tty4

#tty5

#tty6

#tty7

#tty8

-意味着root仅仅被允许在tty1终端登录。

/etc/inittab文件中有如下一段话:

  # Run gettys in standard runlevels

  1:2345:respawn:/sbin/mingetty tty1

  2:2345:respawn:/sbin/mingetty tty2

  #3:2345:respawn:/sbin/mingetty tty3

  #4:2345:respawn:/sbin/mingetty tty4

  #5:2345:respawn:/sbin/mingetty tty5

  #6:2345:respawn:/sbin/mingetty tty6

 

  系统默认的可以使用6个控制台,即Alt F1,Alt F2...,这里在3456前面加上“#”,

注释该句话,这样现在只有两个控制台可供使用,最好保留两个。然后重新启动init进程,改动即可生效!

 /sbin/init q  init的重新启动

 

◆13. 特别的帐号

禁止所有默认的被操作系统本身启动的且不需要的帐号,当你第一次装上系统时就应该做此检查,Linux提供了各种帐号,你可能不需要,如果你不需要这个帐号,就移走它,你有的帐号越多,就越容易受到攻击。

为删除你系统上的用户,用下面的命令:

[root@deep]# userdel username

为删除你系统上的组用户帐号,用下面的命令:

[root@deep]# groupdel username

在终端上打入下面的命令删掉下面的用户。

[root@deep]# userdel adm

[root@deep]# userdel lp

[root@deep]# userdel sync

[root@deep]# userdel shutdown

[root@deep]# userdel halt

[root@deep]# userdel mail

如果你不用sendmail服务器,procmail.mailx,就删除这个帐号。

[root@deep]# userdel news

[root@deep]# userdel uucp

[root@deep]# userdel operator

[root@deep]# userdel games

如果你不用X windows 服务器,就删掉这个帐号。

[root@deep]# userdel gopher

[root@deep]# userdel ftp

如果你不允许匿名FTP,就删掉这个用户帐号。

===

打入下面的命令删除组帐号

[root@deep]# groupdel adm

[root@deep]# groupdel lp

[root@deep]# groupdel mail

如不用Sendmail服务器,删除这个组帐号

[root@deep]# groupdel news

[root@deep]# groupdel uucp

[root@deep]# groupdel games

如你不用X Windows,删除这个组帐号

[root@deep]# groupdel dip

[root@deep]# groupdel pppusers

[root@deep]# groupdel popusers

如果你不用POP服务器,删除这个组帐号

[root@deep]# groupdel slipusers

用下面的命令加需要的用户帐号

[root@deep]# useradd username

用下面的命令改变用户口令

[root@deep]# passwd username

chattr命令给下面的文件加上不可更改属性。

[root@deep]# chattr i /etc/passwd

[root@deep]# chattr i /etc/shadow

[root@deep]# chattr i /etc/group

[root@deep]# chattr i /etc/gshadow

◆14、阻止任何人su作为root.

如果你不想任何人能够su作为root,你能编辑/etc/pam.d/su加下面的行:

auth sufficient /lib/security/pam_rootok.so debug

auth required /lib/security/pam_wheel.so group=isd

意味着仅仅isd组的用户可以su作为root.

然后,如果你希望用户adminsu作为root.就运行下面的命令。

[root@deep]# usermod -G10 admin

 

 

◆15、资源限制

对你的系统上所有的用户设置资源限制可以防止DoS类型攻击(denial of service attacks

如最大进程数,内存数量等。例如,对所有用户的限制象下面这样:

编辑/etc/security/limits.con加:

* hard core 0

* hard rss 5000

* hard nproc 20

你也必须编辑/etc/pam.d/login文件加/检查这一行的存在。

session required /lib/security/pam_limits.so

上面的命令禁止core files“core 0”,限制进程数为“nproc 50“,且限制内存使用

5M“rss 5000”

◆16The /etc/lilo.conf file

a Add: restricted

加这一行到每一个引导映像下面,就这表明如果你引导时用(linux single),则需要一个password.

b Add: password=some_password

当与restricted联合用,且正常引导时,需要用户输入密码,你也要确保lilo.conf

文件不能被不属于root的用户可读,也免看到密码明文。下面是例子:

编辑/etc/lilo.conf加:

====

boot=/dev/sda

map=/boot/map

install=/boot/boot.b

prompt

timeout=50

Default=linux

restricted ?add this line.

password=some_password ?add this line.

image=/boot/vmlinuz-2.2.12-20

label=linux

initrd=/boot/initrd-2.2.12-10.img

root=/dev/sda6

read-only

[root@deep]# chmod 600 /etc/lilo.conf (不再能被其他用户可读).

[root@deep]# /sbin/lilo -v (更新lilo配置).

[root@deep]# chattr i /etc/lilo.conf(阻止该文件被修改)

◆17、禁止 Control-Alt-Delete 重启动机器命令

阅读(620) | 评论(0) | 转发(0) |
0

上一篇:awstats的安装

下一篇:windows7显示ie

给主人留下些什么吧!~~

[root@deep]# vi /etc/inittab

  • 注:暂存的内容只能恢复到当前文章的编辑器中,如需恢复到其他文章中,请编辑该文章并从暂存箱中恢复;或者直接复制以上内容,手工恢复到相关文章。
  • 恢复到编辑器   关闭
  • function sendPV(){ var pvTrack = new PvTrack(); pvTrack.type = 35; // 频道类别ID pvTrack.channel = 189; // 频道ID pvTrack.pageType = 0; pvTrack.track(); } window.setTimeout("sendPV()", 0); var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-20237423-2']); _gaq.push(['_setDomainName', '.chinaunix.net']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? '' : '') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
    var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F0ee5e8cdc4d43389b3d1bfd76e83216b' type='text/javascript'%3E%3C/script%3E"));