一个Linux系统安全设置的Shell脚本的分享(适用CentOS)

 更新时间:2014年06月13日 09:03:43   投稿:junjie  
这篇文章主要介绍了一个设置Linux系统安全的Shell脚本的分享,适用CentOS,包含大部份的安全设置,只需执行脚本就可以得到一个相对安全的Linux系统了,需要的朋友可以参考下

我们将常用的系统安全配置制作为一个shell脚本,只需要在服务器上运行这个shell脚本即可完成安全设置。

linux的系统安全设 置Shell脚本是第二次更新,已经大量应用在某大型媒体网站体系中,加入了之前没有想到的一些安全设置。使用方法将其复制,保存为一个shell文件, 比如security.sh.将其上传到Linux服务器上,执行sh security.sh,就可以使用该脚本了!

复制代码 代码如下:
#!/bin/sh
# desc: setup linux system security
#account setup

passwd -l xfs
passwd -l news
passwd -l nscd
passwd -l dbus
passwd -l vcsa
passwd -l games
passwd -l nobody
passwd -l avahi
passwd -l haldaemon
passwd -l gopher
passwd -l ftp
passwd -l mailnull
passwd -l pcap
passwd -l mail
passwd -l shutdown
passwd -l halt
passwd -l uucp
passwd -l operator
passwd -l sync
passwd -l adm
passwd -l lp

# chattr /etc/passwd /etc/shadow
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow

# add continue input failure 3 ,passwd unlock time 5 minite
sed -i 's#auth required pam_env.so#auth required pam_env.sonauth required pam_tally.so onerr=fail deny=3 unlock_time=300nauth required /lib/security/$ISA/pam_tally.so onerr=fail deny=3 unlock_time=300#' /etc/pam.d/system-auth
# system timeout 5 minite auto logout
echo "TMOUT=300" >>/etc/profile

# will system save history command list to 10
sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile

# enable /etc/profile go!
source /etc/profile

# add syncookie enable /etc/sysctl.conf
echo "net.ipv4.tcp_syncookies=1" >> /etc/sysctl.conf

sysctl -p # exec sysctl.conf enable
# optimizer sshd_config

sed -i "s/#MaxAuthTries 6/MaxAuthTries 6/" /etc/ssh/sshd_config
sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config

# limit chmod important commands
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 /bin/vi
chmod 700 /usr/bin/which
chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/make
chmod 700 /bin/rpm

# history security

chattr +a /root/.bash_history
chattr +i /root/.bash_history

# write important command md5
cat > list << "EOF" && /bin/ping /bin/finger /usr/bin/who /usr/bin/w /usr/bin/locate /usr/bin/whereis /sbin/ifconfig /bin/pico /bin/vi /usr/bin/vim /usr/bin/which /usr/bin/gcc /usr/bin/make /bin/rpm EOF for i in `cat list` do if [ ! -x $i ];then echo "$i not found,no md5sum!" else md5sum $i >> /var/log/`hostname`.log
fi
done
rm -f list

相关文章

  • shell实现自动备份mysql、整站数据的两个脚本分享

    shell实现自动备份mysql、整站数据的两个脚本分享

    这篇文章主要介绍了shell实现自动备份mysql、整站数据的两个脚本分享,使用了cron实现实现定时备份,并会自动删除N天前的备份,以及自动FTP上传到别的服务器,需要的朋友可以参考下
    2014-06-06
  • Shell根据web日志计算平均连接时间功能

    Shell根据web日志计算平均连接时间功能

    这篇文章主要介绍了Shell根据web日志计算平均连接时间功能,本文给出了原代码和自己修改后的代码,需要的朋友可以参考下
    2014-12-12
  • 一文学会使用Linux内核模块&proc实例统计所有进程信息

    一文学会使用Linux内核模块&proc实例统计所有进程信息

    这篇文章主要介绍了使用Linux内核模块&proc实例统计所有进程信息详解,
    2023-05-05
  • Linux内核链表实现过程

    Linux内核链表实现过程

    本文讲解Linux内核链表实现的过程,说了链表的定义及初始化宏定义、操作和删除操作等内容,详细看下面
    2013-11-11
  • shell -z和-n的使用区别

    shell -z和-n的使用区别

    本文将深入探讨shell命令中的-z和-n选项,通过详细解释这两个选项的工作原理和用途,帮助读者更好地理解和掌握Shell脚本编写,感兴趣的可以了解一下
    2024-01-01
  • 在Linux命令行中终止进程的操作命令

    在Linux命令行中终止进程的操作命令

    如果你想在linux上停止某个进程,你会怎么操作,本文小编给大家详细介绍了如何在 Linux 命令行中终止进程,文中通过代码示例给大家介绍的非常详细,需要的朋友可以参考下
    2023-12-12
  • 深入理解Linux中的grep命令

    深入理解Linux中的grep命令

    大家都知道grep是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。这篇文章给大家详细的介绍了Linux中的grep命令,相信对大家的学习和理解很有帮助,有需要的朋友们可以参考借鉴,感兴趣下面来一起学习学习吧。
    2016-11-11
  • shell脚本一键安装php7的实例(推荐)

    shell脚本一键安装php7的实例(推荐)

    下面小编就为大家带来一篇shell脚本一键安装php7的实例(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-10-10
  • linux patch 命令小结(收藏)

    linux patch 命令小结(收藏)

    说到patch命令,就不得不提到diff命令,也就是制作patch的必要工具。这篇文章主要介绍了linux patch 命令小结,需要的朋友可以参考下
    2017-02-02
  • 备份网站内容的shell脚本代码

    备份网站内容的shell脚本代码

    备份网站内容的shell脚本代码,需要的朋友可以参考下
    2013-02-02

最新评论