当前位置: 首页 > 编程笔记 >

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

拓拔弘化
2023-03-14
本文向大家介绍一个Linux系统安全设置的Shell脚本的分享(适用CentOS),包括了一个Linux系统安全设置的Shell脚本的分享(适用CentOS)的使用技巧和注意事项,需要的朋友参考一下

我们将常用的系统安全配置制作为一个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脚本分享,包括了实时查看系统流量的Shell脚本分享的使用技巧和注意事项,需要的朋友参考一下

  • 本文向大家介绍实现释放CentOS系统内存的Shell脚本分享,包括了实现释放CentOS系统内存的Shell脚本分享的使用技巧和注意事项,需要的朋友参考一下 这几天发现CentOS系统内存一直涨,即使把apache和mysql关闭了,内存也不释放,可以使用以下脚本来释放内存:   脚本内容:   利用系统crontab实现每天自动运行: 输入以下内容: 每天0点释放一次内存,这个时间可以根据自己

  • 本文向大家介绍CentOS 6.x系统升级Python到2.7版本的Shell脚本分享,包括了CentOS 6.x系统升级Python到2.7版本的Shell脚本分享的使用技巧和注意事项,需要的朋友参考一下 在CentOS 6.x上,默认自带的Python是2.6.x版本,这个版本的Python有点老了,比如“collections.OrderedDict”就是2.7才有的,而且著名的Python

  • 本文向大家介绍3个备份系统文件并邮件发送的Shell脚本分享,包括了3个备份系统文件并邮件发送的Shell脚本分享的使用技巧和注意事项,需要的朋友参考一下 1.安装MUTT邮件客户端 2.创建脚本 版本一: 版本二:推荐 注:此版本将附件分开发送,对邮箱同时发送多个大附件有收不到的几率的情况,可按照如下版本重新配置 版本三: 实现rar分割并附件发送 推荐附件超过50M的用户使用 注:如果报如下错

  • 本文向大家介绍自己常用的一些shell脚本分享,包括了自己常用的一些shell脚本分享的使用技巧和注意事项,需要的朋友参考一下 自己写了一下小的shell实例,虽然很小,但所有的大的程序都是由小的模块堆积起来的,程序员一定要懂得一种脚本的书写,而我,只会在linux下工作,所以就只能写linux的shell脚本了,呵呵,本文会陆续更新,给自己加油! 1.模拟linnux登录shell 2.比较两个

  • 本文向大家介绍一个简洁的全自动安装LNMP服务器环境的Shell脚本分享,包括了一个简洁的全自动安装LNMP服务器环境的Shell脚本分享的使用技巧和注意事项,需要的朋友参考一下 此脚本在生产服务器上使用了一年多,本脚本崇尚简单唯美,只需要一个脚本就可以在任何一台有网络的服务器上自动配置LNMP。 本脚本会在脚本执行目录下,建packages目录用于存放LNMP所需要的软件。大家安装完可以删除该目