Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use shell script safely in linux system

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to safely use the shell script in the linux system, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

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

# author:coralzd

# powered by www.freebsdsystem.org

# version 0.1.2 written by 2011.05.03

# 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.so\ nauth required pam_tally.so onerr=fail deny=3 unlock_time=300\ nauth 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

The above is how to safely use shell scripts in linux systems. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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: 284

*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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report