脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - shell - 一个Linux系统安全设置的Shell脚本的分享(适用CentOS)

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

2023-02-10 18:34shell教程网 shell

这篇文章主要介绍了一个设置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学习shell脚本之前的基础知识[图文]

    学习shell脚本之前的基础知识[图文]

    在学习shell脚本之前,需要你了解很多关于shell的知识,这些知识是编写shell脚本的基础,所以希望你能够熟练的掌握...

    shell教程网6062022-12-19
  • shell一个下载网页图片的shell脚本

    一个下载网页图片的shell脚本

    这篇文章主要介绍了一个下载网页图片的shell脚本,需要的朋友可以参考下...

    shell教程网6452022-12-29
  • shell杀掉oracle在线用户脚本分享

    杀掉oracle在线用户脚本分享

    这篇文章主要介绍了杀掉oracle在线用户脚本,需要的朋友可以参考下...

    脚本之家6502022-12-29
  • shell利用kernel提供的接口打印进程号(pid)

    利用kernel提供的接口打印进程号(pid)

    我们知道linux是模块化的内核。实现模块、利用kernel提供的接口,首先了解写模块的基本框架。下面的c文件就是最基本的框架,当然还有怎样添加一些符号...

    脚本之家8352022-12-22
  • shellshell监控脚本 准备工作分享

    shell监控脚本 准备工作分享

    这篇文章主要介绍了在编写监控功能脚本需要做的一些工作,需要的朋友可以参考下...

    shell教程网7452022-12-24
  • shell如何调试Linux shell脚本

    如何调试Linux shell脚本

    最简单的调试命令当然是使用echo命令。您可以使用echo在任何怀疑出错的地方打印任何变量值。这也是绝大多数的shell程序员要花费80%的时间来调试程序的原...

    shell教程网5492022-12-20
  • shelllinux bash字符串处理大全

    linux bash字符串处理大全

    linux bash字符串处理大全,需要的朋友可以参考下...

    脚本之家10882022-12-15
  • shell如何在 Bash 脚本中分割字符串

    如何在 Bash 脚本中分割字符串

    假设我们有一个由逗号或者下划线隔开的多个单词组成的字符串,需要拆分这个字符串提取各个单词。 可以使用内部字段分隔符( Internal Field Separator,I...

    TIAP9252022-12-06