师父:

http://debugo.com/rhel6-server-security-hardening-script/

不认识:

profile:http://linux.chinaitlab.com/administer/820910.html



  • disabling services

    原则:只保留最小化安装(不包含可视化桌面的那个最小)的系统服务+用户安装的服务。其他服务一律干掉。(附非官方最小安装服务列表:http://jiaxl.blog.51cto.com/3064605/954239

chkconfig NetworkManager off
chkconfig abrt-ccpp off
chkconfig abrtd off
chkconfig acpid off
chkconfig atd off 
chkconfig bluetooth off
chkconfig certmonger off
chkconfig cpuspeed off
chkconfig cgconfig off
chkconfig cpuspeed off
chkconfig ip6tables off
chkconfig iptables off
chkconfig libvirt-guests off
chkconfig netconsole off
chkconfig netfs off
chkconfig nfslock off
chkconfig postfix off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig rhnsd off
chkconfig restorecond off
chkconfig httpd off
chkconfig vsftpd off


  • config ntp client

crontab -e
38 * * * * /usr/sbin/ntpdate 172.18.5.193 >>/root/ntpdate.log 2>&1

    ps:

    38 ****这个火星文是cron的定时接口。详情见链接:

    http://www.poluoluo.com/jzxy/201009/94264.html


    >和>>都是重定向输出
    1> 指标准信息输出路径(也就是默认的输出方式)
    2> 指错误信息输出路径
    2>&1 指将标准信息输出路径指定为错误信息输出路径(也就是都输出在一起)

    补充问题4<&0:
    <和<<都是重定向输入
    <0指标准输入路径
    4<&0 指的是将文件描述符4指定为标准输入(实际可选4到9之间任意一个数字)


    习惯上
    标准输入(standard input)的文件描述符是 0
    标准输出(standard output)是 1
    标准错误(standard error)是 2


    > 会覆盖已有的文件内容,而>>会附加到已有内容之后。


  • global env variables

    这是为了永久修改时区

vim /etc/profile
# adding.
export TZ=Asia/Shanghai
export TMOUT=1800
comment if-clause of umask statement,and use 'umask 022' to replace it.

    ps:

    在.profile中使用export语句,它的作用是将变量设置在SHELL环境中,以在任意路径下使用。

    comment :說明而已!好像是设置了新建文件的权限。

  • use pam(可插拔认证模块 Pluggable Authentication Modules)(还是有待学习)

    控制能su到root的用户。

vim /etc/pam.d/su:
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
# auth            sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth            required        pam_wheel.so use_uid
# only users in wheel group can su to root
# you can modify user to wheel group like this: usermod -G10 username
# then check: /etc/groups

关于PAM的入门介绍:http://www.infoq.com/cn/articles/linux-pam-one

  • password policy

(1)/etc/pam.d/passwd
   password   include      system-auth
   
   # include 表示在验证错误时,系统会跳出当前登入
   # substack 表示在验证错误时,不会提示用户是在这一步错误了,直到所有验证步骤结束返回错误信息。
(2)修改文件/etc/pam.d/system-auth
   password requisite pam_cracklib.so minlen=8 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1
# minlen the length of password
# lcredit ucredit dcredit ocredit表示小写、大写、数字、符合,设定值为为负数如-1表示至少1个,为正数如3表示最多3个
  • create user without creating home

    这个文件给出了对用户的一系列定义:

    CREATE_HOME 是否为新建用户创建home目录

    UMASK 用户新建文件的权限

/etc/login.defs
CREATE_HOME    no
UMASK 027
  • /etc/ssh/sshd_config

PermitRootLogin no
MaxAuthTries 3
MaxSessions 5
  • lock accounts

    需要锁定的账号:adm、lp、sync、shutdown、halt、mail、news、uucp、operator、games、gopher、ftp、mailnull、
    nfsnobody、nobody、pegasus、http
    参考配置
    (1)***用户:#userdel username;
    (2)锁定用户:#passwd -l username
    (3)解锁用户:#passwd -u username
    (4)禁止用户交互登录:修改/etc/passwd文件,用户shell修改为/sbin/nologin
    补充说明

passwd -l adm
passwd -l lp
passwd -l sync
passwd -l shutdown
passwd -l halt
passwd -l mail
passwd -l news
passwd -l uucp
passwd -l operator
passwd -l games
passwd -l gopher
passwd -l ftp
passwd -l mailnull
passwd -l nfsnobody
passwd -l nobody
passwd -l pegasus
passwd -l http
  • banner

    这是发挥逗比技能的舞台 = =。系统登录时的banner 。。。也是只针对文本界面的。。。

#vim /etc/motd (message of the day)
Authorized users only. All activities will be monitored and reported.

    ftp的配置文件/etc/vsftpd/vsftpd.conf
    配置文件的全部技能:
http://blog.csdn.net/yichi7758/article/details/4640014

    ftp的banner:

#vim /etc/vsftpd/vsftpd.conf
ftpd_banner="Authorized users only.All activity may be monitored and reported."

    ftp的匿名登录:

anonymous_enable=NO
  • disable Control-Alt-Delete

    修改/etc/init/control-alt-delete.conf文件,注释如下内容:

exec /sbin/shutdown -r now "Control-Alt-Delete pressed"

    ps:这一行只是针对费图形界面进行配置。图形界面依然可以激活重启对话框。

  • syslog

#vim /etc/rsyslog.conf
*.err;kern.debug;daemon.notice;                         /var/log/messages(直接添加行)
authpriv.*    /var/log/secure(已经有了,确定一下)
重启syslog服务
/etc/init.d/rsyslog restart
修改log目录权限
#chmod 640 -R /var/log/