当前位置: 移动技术网 > 网络运营>服务器>Linux > 加固Linux系统的三种方法总结

加固Linux系统的三种方法总结

2017年12月08日  | 移动技术网网络运营  | 我要评论

加固linux系统的三种方法总结

linux命令行历史加固

通过配置系统环境变量实现记录用户在命令行执行的命令。

vim /etc/profile.d/system_monitor.sh
# 添加下面代码
export tmout=600
readonly tmout
#history
user_ip=`who -u am i 2>/dev/null | awk '{print $nf}' | sed -e 's/[()]//g'`
histdir=/usr/share/.history
if [ -z $user_ip ]; then
user_ip=`hostname`
fi
if [ ! -d $histdir ]; then
mkdir -p $histdir
chmod 777 $histdir
fi
if [ ! -d $histdir/${logname} ]; then
mkdir -p $histdir/${logname}
chmod 300 $histdir/${logname}
fi
export histsize=4000
dt=`date +%y%m%d_%h%m%s`
export histfile="$histdir/${logname}/${user_ip}.history.$dt"
export histtimeformat="[%y.%m.%d %h:%m:%s]"
chmod 600 $histfile/${logname}/*.history* 2>/dev/null

重新加载环境变量

source /etc/profile.d/system_monitor.sh

效果:每个帐号每次的登录ip以及运行命令都会记录在该目录如下:

[root@localhost ~]# ll /usr/share/.history/root/
total 8
-rw-------. 1 root root 236 apr 23 21:49 1.180.212.137.history.20170423_214918
-rw-------. 1 root root 564 apr 23 21:54 1.180.212.137.history.20170423_214957

crond调用黑白名单

cron有它自己内建的特性,这特性允许定义哪些人能哪些人不能跑任务。 这是通过两个文件/etc/cron.allow 和 /etc/cron.deny控制的。要锁定在用cron的用户时可以简单的将其名字写到corn.deny里,而要允许用户跑cron时将其名字加到cron.allow即可。如果你要禁止所有用户,仅允许root用户。如下:

# echo 'root' >> /etc/cron.allow
# echo 'all' >> /etc/cron.deny

ssh服务禁止root登录

1、不要使用默认端口,修改方式;

port 3714

2、不要使用第一版协议;

protocol 2

3、限制可登录的用户;

allowusers user1 user2 #仅允许user1和user2用户登录

4、设定空闲会话超时时长;

5、利用防火墙设置ssh的远程访问策略;仅允许来自于指定网络中的主机访问;

6、仅监听于指定的ip地址;

listenaddress

7、基于口令认证时,要使用强密码策略;

# 使用mkpasswd命令生成密码;
mkpasswd -l 15 -s 3 -d 3 -c 3

8、最后使用基于密钥进行认证

9、禁止使用空密码,默认启用;

permitemptypasswords no:是否允许空密码登录;

10、禁止管理员直接登录;

permitrootlogin yes # 是否允许管理员直接登录;安全起见,建议为no;

11、限制ssh访问频度和并发在线;

12、做好日志分析;

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网