Linux的系统安全设置Shell脚本

#!/bin/sh
# desc: setup linux system security
# powered by www.lvtao.net
#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

执行sh security.sh

时间: 2024-08-30 13:33:49

Linux的系统安全设置Shell脚本的相关文章

linux服务器系统负载监控-shell脚本

一.监控服务器系统负载情况: 1.用uptime命令查看当前负载情况(1分钟,5分钟,15分钟平均负载情况) # uptime   15:43:59 up 186 days, 20:04,  1 user,  load average:  0.01,    0.02,   0.00 系统负荷的经验法则:(详情参考:http://blog.csdn.net/skyline_loafer/article/details/26940539)(1) 主要观察"15分钟系统负荷",将它作为电脑正

Linux之进程管理及Shell脚本

使用!来调用过往命令 !! 重复执行上一条指令 !a 重复执行上一条以a为首的指令 !nubmer 重复执行上一条在history表中记录号码为number的指令 !-number重复执行前第number条指令 ailas abc='cd xxxxxxxxxxx/xxxxxxxx/xxxxxxxxxxxxx' unalias abc " "将一串字符当成字符串来看,可以转译特殊字符 ' '将一串字符当成字符串来看,无法转译特殊字符 ·能够返回命令执行的结果 echo `uname -a

linux c程序中获取shell脚本输出的实现方法

linux c程序中获取shell脚本输出的实现方法 1. 前言Unix界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些夸张,但不可否认的是,借助脚本确实能够极大的简化一些编程工作.比如实现一个ping程序来测试网络的连通性,实现ping函数需要写上200~300行代码,为什么不能直接调用系统的ping命令呢?通常在程序中通过 system函数来调用shell命令.但是,system函数仅返回命令是否执行成功,而我们可能需要获得shell命令在控制台上输出的结果.例如,执行外部

mac设置shell脚本开机自启动

最近需要做分布式架构的网站,目前一直在调试阶段,每次开机的时候都要启动一大堆工具,比如zookeeper.activemq.redis.nginx等等,不厌其烦. 在网上搜了下mac如何设置shell脚本开机自启动,记录一下,方便自己也方便大家. 1.首先写一个sh脚本,比如: 1 cd ~/Documents 2 mkdir haha 代码很简单,进入Documents文件夹,建立haha目录,保存为run.sh 2.修改run.sh权限 sudo chmod 777 run.sh 3.右键点

Linux自动安装JDK的shell脚本

Linux自动安装JDK的shell脚本 A:本脚本运行的机器,Linux B:待安装JDK的机器, Linux 首先在脚本运行的机器A上确定可以ssh无密码登录到待安装jdk的机器B上,然后就可以在A上运行本脚本: $ ./install-jdk.sh B的IP or: $ ./install-jdk.sh "B的IP" "JDK的URI" 就可以在机器B上安装JDK.jdk使用的tar包需要用户自己设定DEFAULT_JDK_SRC=?,保证可以wget得到即可

Linux问题:Crontab 执行shell脚本时相对路径的问题,不能识别。

问题描述:在linux中的直接执行shell脚本可以用相对路径找到文件,但是如果通过计划任务crontab执行shell脚本时,却不能通过相对路径找到文件! 例子: shell脚本文件代码~ #! /bin/sh Logfile = './1.txt'; date >> $Logfile; echo '------'; 直接执行shell脚本,可以在1.txt文件中看到执行结果,但是如果用crontab计划任务去执行,却在1.txt中看不到执行结果.换成绝对路径就可以,代码如下 #! /bin

Linux 防止rm -rf 误删Shell脚本

#!/bin/bash #:set ff=unix #:set nobomb #-*- coding:utf-8 -*- ###################################################################### ## Filename:     Trash.py ## ## Copyright (C) 2014.6 ## Author:        [email protected]@qq.com ## ## Description:   S

【sehll学习】linux运维一个简单shell脚本监控系统内存

学习shell脚本入门后,慢慢要尝试编写一些脚本练练手,在这先简单的学习写个系统内存的监控. 1.首先先要确定一下截取一下需要关注的内存使用值,可使用free 命令来操作 free -m 显示 一般在监控内存是我们都是截取 第三行(-/+ buffers/cache)的值.确定后可以使用管道线和grep命令来获取这个的值. free -m | grep - | awk  '{print $4}' 获取到他的值为  858 当中 grep -  就是匹配一下要选取的内容,不太熟悉的可以学习一下gr

linux/unix系统间文备份脚本

这是我之前写的一个shell脚本,用于linux/unix系统间的文件自动备份. 脚本的主要功能有: 用于不同服务器间当天的文件的同步或拷贝:需要expect命令支持,RHEL和AIX测试正常,需要expect命令支持(unix系统需要修改脚本第一行的#!/bin/bash为系统SHELL): 使用要求: 系统expect命令可用:目标(远程)设备文件夹存在且可有相应权限.适用情况(以下场景测试正常):        一台设备同一文件夹向一台或多台远程设备相同或不同文件夹拷贝文件