Linux系统 安全加固

一. 账号安全

  1. 账号锁定
passwd -l scu
passwd -u scu

本质:在/etc/shadow密码列前增加"!"

  1. 口令策略
vi /etc/login.defs
PASS_MAX_DAYS   90		# 密码最长使用天数
PASS_MIN_DAYS   0
PASS_WARN_AGE   7		# 密码到期提前预警天数
PASS_MIN_LEN    8		# 密码最小长度,若使用pam_cracklib,该参数不再有效 
  1. 禁止非wheel组用户su至root
vi /etc/pam.d/su
auth  required  /lib/security/pam_wheel.so    # 默认group=wheel

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

vi /etc/login.defs (Redhat)
SU_WHEEL_ONLY yes
  1. 禁止新增用户、删除用户和修改密码
chattr +i /etc/passwd
chattr +i /etc/shadow
  1. root密码不过期
chage -M 99999 root
  1. 忘记root密码
  • 重启进入单人模式,使用passwd修改
  • 以Live CD开机后挂载根目录,清空/etc/shadow中root密码字段

二. 最小化服务

  1. 运行级别
runlevel (who -r)
  1. 停止和禁用无关服务
chkconfig --list
service nfs stop
chkconfig --level 3 nfs off

chkconfig --level 3,5 nfs on 

三. 数据访问控制

  1. 设置系统全局umask
vi /etc/profile
umask 027
  1. 欢迎信息,不要在配置中暴露系统信息,删除\r, \l等内核信息
/etc/redhat-release
/etc/SuSE-release
/etc/issue
/etc/motd
  1. 增强/tmp目录的安全性
# 备份/tmp目录
mdkir /tmp_backup
cp -pr /tmp/* /tmp_backup  或者cp -R /tmp/ /tmp_backup

# 创建100M空文件
dd if=/dev/zero of=/dev/tmp bs=1024 count=100000

# 设置为扩展文件系统
mke2fs /dev/tmp

# 挂载文件系统
chmod 0777 /tmp
mount -o loop,rw,nosuid,noexec /dev/tmp /tmp

# 还原备份文件
cp -pr /tmp_backup/* /tmp
rm -rf /tmp_backup

# 添加到fstab
vi /etc/fstab
/dev/tmp	/tmp	 ext3   loop,rw,nosuid,noexec  0  0
  1. 增强/dev/shm的安全性
vi /etc/fstab
shm  /dev/shm   tmpfs   defaults,nosuid,noexec,rw,size=24541576K  0 0
  1. 文件系统权限
# 所有suid和sgid的文件
find / -type f -perm -4000 -o -perm 2000 | xargs ls -lg

# 没有属主或属组的文件
find / -nouser -o -nogroup

# group或others具有可读权限
find / -type f -perm -2 -o -perm -20 | xargs ls -lg
find / -type d -perm -2 -o -perm -20 | xargs ls -ldg

# suid和sgid文件,MD5值检查
find / -user root -type f -perm 2000 -exec md5sum {} \;
find / -user root -type f -perm 4000 -exec md5sum {} \;

四. 网络访问控制

  1. 开启ssh
ps -ef | grep sshd
service sshd start
  1. 限定ssh远程登录IP
vi /etc/ssh/sshd_config
AllowUsers *@10.134.*.*

service sshd restart
  1. 禁止远程root登录
vi /etc/ssh/sshd_config
PermitRootLogin no
  1. 限定信任主机
从配置文件中删除不必要的主机
/etc/hosts.equiv
$HOME/.rhosts
  1. 屏蔽Banner信息
vi /etc/ssh/sshd_config
Banner NONE

vi /etc/motd (清空文件)
  1. 防止误使用Ctrl+Alt+Del重启系统
vi /etc/inittab
#ca::ctrlaltdel:/sbin/shutdown -r -t 4 now
  1. SSH安全,禁用sshv1,使用sshv2
vi /etc/ssh/sshd_config
Protocol 2

service sshd restart

ssh -2 root@10.137.5.44
  1. 禁用telnet
vi /etc/xinetd.d/telnet
disable = yes

service xinetd restart
  1. 限制访问inet服务
vi /etc/hosts.deny
ALL : 10.137.5.155
  1. 监听端口
netstat -tulp
lsof -i -n | egrep 'COMMAND|LISTEN|UDP'

五. 用户鉴别

  1. 设置账户最大登录失败次数及锁定时间
vi /etc/pam.d/system-auth

# 连续输错三次密码,锁定用户5分钟
auth required pam_tally.so onerr=fail deny=3 unlock_time=5

# root用户遵循上面的规则,并锁定10分钟
auth required pam_tally.so deny=3 unlock_time=5 even_deny_root root_unlock_time=10 

# 解锁用户
faillog -u bmp -r	
faillog -r
  1. 设置自动注销时间
vi /etc/profile
export TMOUT=600  (600seconds)
  1. 限制ftp用户登录
vi /etc/ftpusers
root	(禁止root用户登录ftp)
  1. 设置命令历史数
vi /etc/profile
export HISTSIZE=1000
export HISTFILESIZE=1000
  1. 禁用代码编译
# 添加编译组
groupadd compiler

# 修改编译器属组
cd /usr/bin
chgrp compiler *cc*
chgrp compiler *++*
chgrp compiler ld
chgrp compiler as

# 设置权限
chmod 750 *cc*
chmod 750 *++*
chmod 750 ld
chmod 750 as

# 添加用户到compiler组
vi /etc/group
compiler:x:520:user1,user2
  1. history安全,禁止清除和删除命令历史
chattr +a .bash_history
chattr +i .bash_history

六. 审计策略

  1. 系统日志策略
vi /etc/syslog-ng/syslog-ng.conf
destination messages { file("/var/log/messages"); };
log { source(src); filter(f_messages); destination(messages); };

destination warn { file("/var/log/warn" fsync(yes)); };
log { source(src); filter(f_warn); destination(warn); };

vi /etc/rsyslog.conf (Redhat)
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
authpriv.*                                              /var/log/secure
  1. 系统日志个数和大小
vi /etc/logrotate.conf
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment these to switch compression to bzip2
compresscmd /usr/bin/bzip2
uncompresscmd /usr/bin/bunzip2

vi /etc/logrotate.d/syslog
/var/log/warn /var/log/messages {
    compress
    dateext
    maxage 365
    rotate 99
    missingok
    notifempty
    size +4096k
    create 640 root root
    sharedscripts
    postrotate
        /etc/init.d/syslog reload
    endscript
}
  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值