安装linux系统后调优及安全设置
环境说明:
- [root@server1 ~]# cat /etc/redhat-release
- CentOS release 6.9 (Final)
- [root@server1 ~]# uname -r
- 2.6.-.el6.x86_64
1、更改yum源:
- mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup <<-备份系统自带yum源
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo <<—国内使用阿里云yum源速度比较快
- wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
- 注:镜像官方网址http://mirrors.aliyun.com/
- 如有自建yum仓可以更改成自建yum仓地址信息
2、关闭selinux
- 永久关闭(需要重启系统)
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
- 临时关闭(无需重启)
- setenforce
- 数字0表示Premissive,即给出警告提示,不会阻止操作,相当于disabled
- 数字1表示Enfocing,即表示SELinux为开启状态
- getenforce <<-查看selinux当前状态
3、关闭iptables
- /etc/init.d/iptables stop <<-关闭iptables服务
- /etc/init.d/iptables status <<-查看iptables状态
- chkconfig iptables off <<—开机启动关闭
4、精简开机启动
- chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash <<-关闭服务
- chkconfig --list|grep :on <<-检查开机启动的服务
5、更改字符集(选做)
- cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori
- echo 'LANG="zh_CN.UTF-8"' >/etc/sysconfig/i18n
- source /etc/sysconfig/i18n
- echo $LANG
6、普通用户提权(mmod)
- useradd mmod
- echo |passwd --stdin mmod
- \cp /etc/sudoers /etc/sudoers.ori
- echo "mmod ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers
- tail - /etc/sudoers
- visudo -c
7、时间同步
- echo '#time sync by mmod at 2015-2-1' >>/var/spool/cron/root
- echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
- crontab -l
- 注:集群中有时间服务器,更改成时间服务器地址
8、命令行安全(选配)
- 设置闲置账号超时时间
echo 'export TMOUT=300' >>/etc/profile- 命令行历史记录数
- echo 'export HISTSIZE=5' >>/etc/profile
- echo 'export HISTFILESIZE=5' >>/etc/profile
- tail - /etc/profile
- ./etc/profile
9、加大文件描述
- echo '* - nofile 65535' >>/etc/security/limits.conf
- tail - /etc/security/limits.conf
10、内核优化
- cat >>/etc/sysctl.conf<<EOF
- net.ipv4.tcp_fin_timeout =
- net.ipv4.tcp_tw_reuse =
- net.ipv4.tcp_tw_recycle =
- net.ipv4.tcp_syncookies =
- net.ipv4.tcp_keepalive_time =
- net.ipv4.ip_local_port_range =
- net.ipv4.tcp_max_syn_backlog =
- net.ipv4.tcp_max_tw_buckets =
- net.ipv4.route.gc_timeout =
- net.ipv4.tcp_syn_retries =
- net.ipv4.tcp_synack_retries =
- net.core.somaxconn =
- net.core.netdev_max_backlog =
- net.ipv4.tcp_max_orphans =
- #以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理。
- net.nf_conntrack_max =
- net.netfilter.nf_conntrack_max =
- net.netfilter.nf_conntrack_tcp_timeout_established =
- net.netfilter.nf_conntrack_tcp_timeout_time_wait =
- net.netfilter.nf_conntrack_tcp_timeout_close_wait =
- net.netfilter.nf_conntrack_tcp_timeout_fin_wait =
- EOF
- sysctl –p <<-配置完成后查看
11、下载安装基础软件
- yum install lrzsz nmap tree dos2unix nc -y
12、定时清理邮件服务临时目录垃圾文件
- centos 5版本
- find /var/spool/clientmqueue/ -type f | xargs rm -f
- centos .x版本
- find /var/spool/postfix/maildrop/ -type f | xargs rm -f
- 写成脚本,做定时任务
- mkdir -p /server/scripts/
- echo "find /var/spool/postfix/maildrop/ -type f | xargs rm -f " > /server/scripts/del_mailfile.sh
- echo "00 00 * * * /bin/bash /server/scripts/del_mailfile.sh > /dev/null 2>&1"
13、隐藏linux版本信息显示
- [root@server1 ~]# > /etc/issue
- [root@server1 ~]# > /etc/issue.net
- [root@server1 ~]# cat /etc/issue.net
- [root@server1 ~]# cat /etc/issue
14、锁定关键系统文件,防止被提权篡改
- chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab
- 使用lsattr 进行查看,chattr -i进行解锁
15、为grub菜单加密
- 先利用/sbin/grub-md5-crypt 产生一个MD5密钥串,命令如下:
- [root@m01 ~]# /sbin/grub-md5-crypt
- Password:
- Retype password:
- $$SQxvZ/$AXRHUbkNy9EkDHtmoEoQS0
- 修改grub.conf文件,命令如下:
- [root@m01 ~]# vim /etc/grub.conf
- # grub.conf generated by anaconda
- #
- # Note that you do not have to rerun grub after making changes to this file
- # NOTICE: You have a /boot partition. This means that
- # all kernel and initrd paths are relative to /boot/, eg.
- # root (hd0,)
- # kernel /vmlinuz-version ro root=/dev/sda3
- # initrd /initrd-[generic-]version.img
- #boot=/dev/sda
- default=
- timeout=
- splashimage=(hd0,)/grub/splash.xpm.gz
- hiddenmenu
- passwd --md5 $$SQxvZ/$AXRHUbkNy9EkDHtmoEoQS0
- #注意:password要加在splashimage和title之间,否则无法生效
- title CentOS (2.6.-.el6.x86_64)
- root (hd0,)
- kernel /vmlinuz-2.6.-.el6.x86_64 ro root=UUID=33ec961c-16e1--bdbf-644bfdabf1eb rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF- rd_NO_LV
16、禁止linux系统被ping(选配)
- echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf
- sysctl -p
- 拓展:设置特定ip可以ping
iptables -t filter -I INPUT -p icmp --icmp-type 8 -i eth0 -s 10.0.0.0/24 -j ACCEPT
17、升级具有典型漏洞
- 查看相关软件的版本号,命令如下:
- [root@m01 ~]# rpm -qa openssl openssh bash
- openssl-1.0.1e-.el6.x86_64
- bash-4.1.-.el6.x86_64
- openssh-.3p1-.el6.x86_64
- 升级已知漏洞的软件版本到最新,命令如下:
- yum install openssl openssh bash -y
18、更改ssh服务端远程登录的配置
- 修改默认文件路径
- vim /etc/ssh/sshd_config
- 修改的参数
- port #端口
- PermitEmptyPasswords #是否允许密码为空的用户远程登录
- PermitRootLogin #是否允许root登录
- UseDNS #指定sshd是否应该对远程主机名进行反向解析,以检查主机名是否与其IP地址真实对应。默认yes.建议改成no ,否则可能会导致SSH连接很慢。
- GSSAPIAuthentication no #解决linux之间使用SSH远程连接慢的问题
- ListenAddress #监听指定的IP地址
- 12 批量操作:
- sed -ir '13 iPort 55666\nPermitRootLogin no\nPermitEmptyPasswords no\nUseDNS no\nGSSAPIAuthentication no' /etc/ssh/sshd_config
安装linux系统后调优及安全设置的更多相关文章
- Linux系统调优及安全设置
1.关闭SELinux #临时关闭 setenforce 0 #永久关闭 vim /etc/selinux/config SELINUX=disabled 2.设定运行级别为3 #设定运行级别 vim ...
- Linux:U盘安装Linux系统
前天一个同学找我帮忙安装Linux系统,没有光盘,也不想在虚拟机里安装,在此情况下,我就采用U盘方式来安装Linux系统了.又想到还有其他人可能也不会 使用U盘安装系统,这里就作一个简单的介绍. 1. ...
- 虚拟机安装Linux系统图文教程
虚拟机安装Linux系统图文教程 | 浏览:523 | 更新:2014-09-16 15:31 1 2 3 4 5 6 7 分步阅读 Linux系统的安装 工具/原料 VMware 9.0 虚拟机 L ...
- 使用VMware10虚拟机安装Linux系统(能力工场)
作为IT从业人员,我们经常使用到Linux系统,但是实际开发过程我们通常在Windows平台操作,为了满足工作需要,这个时候我们通常在windows平台安装虚拟机,并在其上建立linux系统,这样就极 ...
- 安装Linux系统,学习Linux操作基础
20189230杨静怡 2018-2019-2 <移动平台开发实践>第1周学习总结 安装Linux系统内容总结 一.学习"基于VirtualBox虚拟机安装Ubuntu图文教程& ...
- VM虚拟机 安装linux系统
首先需要下载VMware10 和CentOS-6.4,我这边提供了百度网盘,可供下载链接:https://pan.baidu.com/s/1vrJUK167xnB2JInLH890fw 密码:r4jj ...
- 虚拟机virtualBox安装linux系统 xshell远程连接linux
虚拟机virtualBox安装linux系统 xshell远程连接linux 虚拟机概念: 通过软件, 使用虚拟化技术虚拟出电脑的硬件环境, 充当真实的电脑使用. 常见的虚拟软件: virtualBo ...
- 部署虚拟环境安装Linux系统
目录 准备工作 安装linux系统 重置root管理员密码 源代码编译 R ...
- 如何在Windows环境下安装Linux系统虚拟机
如何在Windows环境下安装Linux系统虚拟机 本篇经验写给想要入门学习C语言的小白们.Windows系统因为使用窗口图形化,操作简单,功能多样,所以我们在Windows环境下可以做到很多,但想要 ...
随机推荐
- 宝塔中mysql数据库命名小坑
今天在通过宝塔新建网站,添加mysql数据库,名字中间有下划线,发现能够创建成功,但是实际链接后,是没有这个数据库的.是宝塔的原因还是liunx服务器的原因? 不支持下划线的数据库名字吗? 比如 bo ...
- SpringCloud版本问题
兴致勃勃地跟随文档创建并配置Eureka Server工程后,启动准备测试,发现报了java.lang.NoSuchMethodError: org.springframework.boot.buil ...
- ADO.net中DataTable的应用
一.思维导图 二.知识点描述 (1)构造函数 DataTable() 不带参数初始化DataTable类的新实例 DataTable(string tableName) 用指定的表名初始化DataT ...
- yocto-sumo源码解析(八): ProcessServer
从前面章节的论述中,我们知道BitBakeServer实际上是一个ProcessServer,什么是ProcessServer不可不了解. 1. 类的声明: 首先这是一个python的多进程包里面的进 ...
- maven 添加spring/springmvc依赖项
<spring.version>4.3.18.RELEASE</spring.version> <dependencies> <!--添加spring.spr ...
- Metasploit拿Shell
进入metasploit系统 msfconsole Nmap端口扫描 nmap –sV IP(或者域名),如果机器设置有防火墙禁ping,可以使用nmap -P0(或者-Pn) –sV IP(或者域名 ...
- Python中collections模块的使用
本文将详细讲解collections模块中的所有类,和每个类中的方法,从源码和性能的角度剖析. 一个模块主要用来干嘛,有哪些类可以使用,看__init__.py就知道 '''This module i ...
- It isn't possible to write into a document from an asynchronously-loaded
It isn't possible to write into a document from an asynchronously-loaded 今天遇到了一个问题: 通过document.wri ...
- “秒杀”问题的数据库和SQL设计【转载】
“秒杀”问题的数据库和SQL设计 APRIL 21ST, 2015 问题的来源 完全不考虑一致性的方案 表结构 方案 存在的问题 保证单用户不会重复购买 解决超卖问题 方案 优化 提高性能了 鱼与熊掌 ...
- DataGridView 复选框 操作大全
DataGridViewCheckBoxColumn dtCheck = new DataGridViewCheckBoxColumn(); dtCheck.DataPropertyName = &q ...