Linux服务器安全加固(一)

来源:互联网 发布:ubuntu tty7 编辑:程序博客网 时间:2024/05/16 03:08

Linux服务器安全加固

1.创建 SU 用户组


方法:
vi /etc/group
添加一行 wheel:x:10:root,user1,user2
chgrp wheel /bin/su

chmod o-rwx /bin/su


2.SSH禁用root登陆更改默认端口

方法:
vi /etc/ssh/sshd_config
把协议改为 2
PermitRootLogin = no

vi /etc/ssh/sshd_config
Port 22 改为其他端口

重启 sshd /etc/rc.d/init.d/sshd restart


3.禁用代码编译

方法:
添加编译用户组 /usr/sbin/groupadd compiler ,cd /usr/bin
把常见的编译器所属组赋给编译用户组
chgrp compiler *cc*
chgrp compiler *++*
chgrp compiler ld
chgrp compiler as
设置 mysqlaccess 的访问
chgrp root mysqlaccess
设置权限
chmod 750 *cc*

chmod 750 *++*
chmod 750 ld
chmod 750 as
chmod 755 mysqlaccess
把用户添加到组里
修改/etc/group
compiler:x:520:user1,user2


4.限制inet服务

方法:
限制访问 inet 服务
修改/etc/hosts.allow
建议格式:
#Approved IP addresses
ALL:192.168.0.1
ALL:192.168.5.2
#CSV uploader machine
proftpd:10.0.0.5
#pop3 from antwhere
ipop3:ALL
修改/etc/hosts.deny
ALL:ALL EXCEPT localhostENY


5.指定root登陆的tty

方法:
vi /etc/securetty
只留 2 个连接
tty1
tty2


6.禁用特殊账户

方法:
删除账户 userdel name
删除组 groupdel name
锁定特定账户:/usr/sbin/usermod -L -s /bin/false user


7.history配置


避免删除.bash_history 或重定向到/dev/null

方法:
chattr +a .bash_history
chattr +i .bash_history


8.限制非root执行命令


方法:
chmod 700 /bin/ping
chmod 700 /usr/bin/finger
chmod 700 /usr/bin/who
chmod 700 /usr/bin/w
chmod 700 /usr/bin/locate
chmod 700 /usr/bin/whereis
chmod 700 /sbin/ifconfig
chmod 700 /usr/bin/pico
chmod 700 /usr/bin/vi
chmod 700 /usr/bin/which

chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/make
chmod 700 /bin/rpm


9.限制默认登陆密码长度


方法:
vi /etc/login.defs
PASS_M IN_LEN 10


10.检测rookit


方法:
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.md5
首先检查 md5 校验值: md5sum chkrootkit.tar.gz
然后解压安装
tar -zxvf chkrootkit.tar.gz
cd chkrootkit
./configure
make sense
然后运行./chkrootkit
我们可以将其添加到 contrab 使其每天自动扫描:
vi /etc/cron.daily/chkrootkit.sh
#!/bin/bash
# 输入 chkrootkit 的安装目录
cd /root/chkrootkit/
# 输入你想收到检测报告的 email
./chkrootkit | mail -s "Daily chkrootkit from Server Name" your@email.com


11.记录root登录事件


方法:
编辑/root 下的.bashrc ,当有 root 权限的用户登录时发生 email 通知
echo 'ALERT - Root Shell Access (Server Name) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -
d"(" -f2 | cut -d")" -f1`" your@email.com


12.关闭不用的服务和端口


方法:

略...


13.安装配置防火墙


方法:
略...

14.安装暴力破解检测


方法:

a.iptables

b.host.allow host.deny

c.crontab + 脚本 + host.deny

略...

15.内核加固


sysctl.conf 用来加固内核,目的是避免 DOS 和欺骗攻击

方法:
略...






0 0
原创粉丝点击