In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to write a Shell script for Linux system security settings". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
We make the commonly used system security configuration as a shell script, and we only need to run this shell script on the server to complete the security settings.
Linux's system security setting Shell script is the second update, which has been widely used in a large media website system, adding some security settings that were not thought of before. Use the method to copy it and save it as a shell file, such as security.sh. Upload it to the Linux server, execute sh security.sh, and you can use the script!
The code is as follows:
#! / 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 > / var/log/ `hostname`.log
Fi
Done
Rm-f list
This is the end of "how to write a Shell script for Linux system security settings". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.