Linux常用安全设置,linux安全设置可以使用pam_ta


用户管理

用户权限

1)限制root

1

2

echo"tty1">/etc/securetty

chmod700/root

2)密码策略

1

2

3

4

echo"Passwords expire every 180 days"

perl -npe's/PASS_MAX_DAYSs+99999/PASS_MAX_DAYS 180/'-i/etc/login.defs

echo"Passwords may only be changed once a day"

perl -npe's/PASS_MIN_DAYSs+0/PASS_MIN_DAYS 1/g'-i/etc/login.defs

用sha512保护密码而不用md5

1

authconfig --passalgo=sha512 --update

3)umask限制


更改umask为077

1

2

perl -npe's/umasks+0d2/umask 077/g'-i/etc/bashrc

perl -npe's/umasks+0d2/umask 077/g'-i/etc/csh.cshrc

4)Pam修改

1

touch/var/log/tallylog

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

cat<<'EOF'>/etc/pam.d/system-auth

#%PAM-1.0

# This file is auto-generated.

# User changes will be destroyed the next time authconfig is run.

auth required pam_env.so

auth sufficient pam_unix.so nullok try_first_pass

auth requisite pam_succeed_if.so uid >= 500 quiet

auth required pam_deny.so

auth required pam_tally2.so deny=3 onerr=fail unlock_time=60

account required pam_unix.so

account sufficient pam_succeed_if.so uid < 500 quiet

account required pam_permit.so

account required pam_tally2.so per_user

password requisite pam_cracklib.so try_first_pass retry=3 minlen=9 lcredit=-2 ucredit=-2 dcredit=-2 ocredit=-2

password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=10

password required pam_deny.so

session optional pam_keyinit.so revoke

session required pam_limits.so

session [success=1 default=ignore] pam_succeed_if.so serviceincrond quiet use_uid

session required pam_unix.so

EOF

/var/log/tallylog是二进制日志,记录认证失败情况。可以使用pam_tally2 --reset -u username解锁


5)回收闲置用户

1

2

3

4

echo"Idle users will be removed after 15 minutes"

echo"readonly TMOUT=900">>/etc/profile.d/os-security.sh

echo"readonly HISTFILE">>/etc/profile.d/os-security.sh

chmod+x/etc/profile.d/os-security.sh

6)cron和at限制

1

2

3

4

5

6

7

8

echo"Locking down Cron"

touch/etc/cron.allow

chmod600/etc/cron.allow

awk-F:'{print $1}'/etc/passwd|grep-vroot >/etc/cron.deny

echo"Locking down AT"

touch/etc/at.allow

chmod600/etc/at.allow

awk-F:'{print $1}'/etc/passwd|grep-vroot >/etc/at.deny

删除系统特殊的的用户和组

1

2

3

4

5

6

7

8

9

10

11

userdel username

userdel adm

userdel lp

userdelsync

userdelshutdown

userdel halt

userdel news

userdel uucp

userdel operator

userdel games

userdel gopher

以上所删除用户为系统默认创建,但是在常用服务器中基本不使用的一些帐号,但是这些帐号常被黑客利用和攻击服务器。

1

2

3

4

5

6

7

groupdel username

groupdel adm

groupdel lp

groupdel news

groupdel uucp

groupdel games

groupdel dip

同样,以上删除的是系统安装是默认创建的一些组帐号。这样就减少受攻击的机会。

服务管理

关闭系统不使用的服务

1

2

3

4

5

6

7

8

9

10

11

12

chkconfig level 35 apmd off

chkconfig level 35 netfs off

chkconfig level 35 yppasswdd off

chkconfig level 35 ypserv off

chkconfig level 35 dhcpd off?

chkconfig level 35 portmap off

chkconfig level 35 lpd off

chkconfig level 35 nfs off

chkconfig level 35 sendmail off

chkconfig level 35 snmpd off

chkconfig level 35 rstatd off

chkconfig level 35 atd off??

定期更新系统

yum -y update,可以加入到cron job。

ssh服务安全

使用证书登录系统,具体不详述,请看这篇文章http://www.centos.bz/2012/02/strengthen-ssh-security-login-with-certificate/

LAMP安全

系统文件权限

修改init目录文件执行权限

1

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

修改部分系统文件的SUID和SGID的权限

1

2

3

4

5

6

7

8

9

10

11

12

13

chmoda-s/usr/bin/chage

chmoda-s/usr/bin/gpasswd

chmoda-s/usr/bin/wall

chmoda-s/usr/bin/chfn

chmoda-s/usr/bin/chsh

chmoda-s/usr/bin/newgrp

chmoda-s/usr/bin/write

chmoda-s/usr/sbin/usernetctl

chmoda-s/usr/sbin/traceroute

chmoda-s/bin/mount

chmoda-s/bin/umount

chmoda-s/bin/ping

chmoda-s/sbin/netreport

修改系统引导文件

1

2

chmod600/etc/grub.conf

chattr +i/etc/grub.conf

日志管理

1、系统引导日志

dmesg


使用 dmesg 命令可以快速查看最后一次系统引导的引导日志。通常它的内容会很多,所以您往往会希望将其通过管道传输到一个阅读器。

2、系统运行日志

A、Linux日志存储在 /var/log 目录中。


这里有几个由系统维护的日志文件,但其他服务和程序也可能会把它们的日志放在这里。大多数日志只有 root 才可以读,不过只需要修改文件的访问权限就可以让其他人可读。


以下是常用的系统日志文件名称及其描述:


lastlog 记录用户最后一次成功登录时间


loginlog 不良的登陆尝试记录?


messages 记录输出到系统主控台以及由syslog系统服务程序产生的消息


utmp 记录当前登录的每个用户


utmpx 扩展的utmp


wtmp 记录每一次用户登录和注销的历史信息 wtmpx 扩展的wtmp


vold.log 记录使用外部介质出现的错误


xferkig 记录Ftp的存取情况 sulog 记录su命令的使用情况


acct 记录每个用户使用过的命令


aculog 拨出自动呼叫记录


B、/var/log/messages


messages 日志是核心系统日志文件。它包含了系统启动时的引导消息,以及系统运行时的其他状态消息。IO 错误、网络错误和其他系统错误都会记录到这个文件中。其他信息,比如某个人的身份切换为 root,也在这里列出。如果服务正在运行,比如 DHCP 服务器,您可以在messages 文件中观察它的活动。通常,/var/log/messages 是您在做故障诊断时首先要查看的文件。


C、/var/log/XFree86.0.log


这个日志记录的是 Xfree86 Xwindows 服务器最后一次执行的结果。如果您在启动到图形模式时遇到了问题,一般情况从这个文件中会找到失败的原因。

网络安全

使用TCP_WRAPPERS

使用TCP_WRAPPERS可以使你的系统安全面对外部入侵。最好的策略就是阻止所有


的主机(在"/etc/hosts.deny" 文件中加入"ALL: ALL@ALL, PARANOID" ),然后再在"/etc/hosts.allow" 文件中加入所有允许访问的主机列表。


第一步:


编辑hosts.deny文件(vi /etc/hosts.deny),加入下面这行


# Deny access to everyone.


ALL: ALL@ALL, PARANOID


这表明除非该地址包好在允许访问的主机列表中,否则阻塞所有的服务和地址。


第二步:


编辑hosts.allow文件(vi /etc/hosts.allow),加入允许访问的主机列表,比


如:


ftp: 202.54.15.99 foo.com


202.54.15.99和 foo.com是允许访问ftp服务的ip地址和主机名称。


第三步:


tcpdchk程序是tepd wrapper设置检查程序。它用来检查你的tcp wrapper设置,并报告发现的潜在的和真实的问题。设置完后,运行下面这个命令:


[Root@kapil /]# tcpdchk

iptables防火墙使用

这里不多介绍,请参考:http://www.linuxboy.net/CentosSecurity/CentosSafe/2013/0801/854.html

相关内容

    暂无相关文章