环境说明:

  1. [root@server1 ~]# cat /etc/redhat-release
  2. CentOS release 6.9 (Final)
  3. [root@server1 ~]# uname -r
  4. 2.6.-.el6.x86_64

1、更改yum源:

  1. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup <<-备份系统自带yum
  2. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo <<—国内使用阿里云yum源速度比较快
  3. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
  4.  
  5. 注:镜像官方网址http://mirrors.aliyun.com/
  6.  
  7. 如有自建yum仓可以更改成自建yum仓地址信息

2、关闭selinux

  1. 永久关闭(需要重启系统)
  2. sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  3.  
  4. 临时关闭(无需重启)
  5. setenforce
  6. 数字0表示Premissive,即给出警告提示,不会阻止操作,相当于disabled
  7. 数字1表示Enfocing,即表示SELinux为开启状态
  8.  
  9. getenforce <<-查看selinux当前状态

3、关闭iptables

  1. /etc/init.d/iptables stop <<-关闭iptables服务
  2. /etc/init.d/iptables status <<-查看iptables状态
  3. chkconfig iptables off <<—开机启动关闭

4、精简开机启动

  1. chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash <<-关闭服务
  2. chkconfig --list|grep :on <<-检查开机启动的服务

5、更改字符集(选做)

  1. cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori
  2. echo 'LANG="zh_CN.UTF-8"' >/etc/sysconfig/i18n
  3. source /etc/sysconfig/i18n
  4. echo $LANG

6、普通用户提权(mmod)

  1. useradd mmod
  2. echo |passwd --stdin mmod
  3. \cp /etc/sudoers /etc/sudoers.ori
  4. echo "mmod ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers
  5. tail - /etc/sudoers
  6. visudo -c

7、时间同步

  1. echo '#time sync by mmod at 2015-2-1' >>/var/spool/cron/root
  2. echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
  3. crontab -l
  4.  
  5. 注:集群中有时间服务器,更改成时间服务器地址

8、命令行安全(选配)

  1. 设置闲置账号超时时间
    echo 'export TMOUT=300' >>/etc/profile
  2.  
  3. 命令行历史记录数
  4. echo 'export HISTSIZE=5' >>/etc/profile
  5. echo 'export HISTFILESIZE=5' >>/etc/profile
  6. tail - /etc/profile
  7. ./etc/profile

9、加大文件描述

  1. echo '* - nofile 65535' >>/etc/security/limits.conf
  2. tail - /etc/security/limits.conf

10、内核优化

  1. cat >>/etc/sysctl.conf<<EOF
  2. net.ipv4.tcp_fin_timeout =
  3. net.ipv4.tcp_tw_reuse =
  4. net.ipv4.tcp_tw_recycle =
  5. net.ipv4.tcp_syncookies =
  6. net.ipv4.tcp_keepalive_time =
  7. net.ipv4.ip_local_port_range =
  8. net.ipv4.tcp_max_syn_backlog =
  9. net.ipv4.tcp_max_tw_buckets =
  10. net.ipv4.route.gc_timeout =
  11. net.ipv4.tcp_syn_retries =
  12. net.ipv4.tcp_synack_retries =
  13. net.core.somaxconn =
  14. net.core.netdev_max_backlog =
  15. net.ipv4.tcp_max_orphans =
  16. #以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理。
  17. net.nf_conntrack_max =
  18. net.netfilter.nf_conntrack_max =
  19. net.netfilter.nf_conntrack_tcp_timeout_established =
  20. net.netfilter.nf_conntrack_tcp_timeout_time_wait =
  21. net.netfilter.nf_conntrack_tcp_timeout_close_wait =
  22. net.netfilter.nf_conntrack_tcp_timeout_fin_wait =
  23. EOF
  24. sysctl p <<-配置完成后查看

11、下载安装基础软件

  1. yum install lrzsz nmap tree dos2unix nc -y

12、定时清理邮件服务临时目录垃圾文件

  1. centos 5版本
  2. find /var/spool/clientmqueue/ -type f | xargs rm -f
  3.  
  4. centos .x版本
  5. find /var/spool/postfix/maildrop/ -type f | xargs rm -f
  6.  
  7. 写成脚本,做定时任务
  8. mkdir -p /server/scripts/
  9. echo "find /var/spool/postfix/maildrop/ -type f | xargs rm -f " > /server/scripts/del_mailfile.sh
  10.  
  11. echo "00 00 * * * /bin/bash /server/scripts/del_mailfile.sh > /dev/null 2>&1"

13、隐藏linux版本信息显示

  1. [root@server1 ~]# > /etc/issue
  2. [root@server1 ~]# > /etc/issue.net
  3. [root@server1 ~]# cat /etc/issue.net
  4. [root@server1 ~]# cat /etc/issue

14、锁定关键系统文件,防止被提权篡改

  1. chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab
  2.  
  3. 使用lsattr 进行查看,chattr -i进行解锁

15、为grub菜单加密

  1. 先利用/sbin/grub-md5-crypt 产生一个MD5密钥串,命令如下:
  2. [root@m01 ~]# /sbin/grub-md5-crypt
  3. Password:
  4. Retype password:
  5. $$SQxvZ/$AXRHUbkNy9EkDHtmoEoQS0
  6.  
  7. 修改grub.conf文件,命令如下:
  8. [root@m01 ~]# vim /etc/grub.conf
  9.  
  10. # grub.conf generated by anaconda
  11. #
  12. # Note that you do not have to rerun grub after making changes to this file
  13. # NOTICE: You have a /boot partition. This means that
  14. # all kernel and initrd paths are relative to /boot/, eg.
  15. # root (hd0,)
  16. # kernel /vmlinuz-version ro root=/dev/sda3
  17. # initrd /initrd-[generic-]version.img
  18. #boot=/dev/sda
  19. default=
  20. timeout=
  21. splashimage=(hd0,)/grub/splash.xpm.gz
  22. hiddenmenu
  23. passwd --md5 $$SQxvZ/$AXRHUbkNy9EkDHtmoEoQS0
  24. #注意:password要加在splashimage和title之间,否则无法生效
  25. title CentOS (2.6.-.el6.x86_64)
  26. root (hd0,)
  27. 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(选配)

  1. echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf
  2.  
  3. sysctl -p
  4.  
  5. 拓展:设置特定ip可以ping
    iptables -t filter -I INPUT -p icmp --icmp-type 8 -i eth0 -s 10.0.0.0/24 -j ACCEPT

17、升级具有典型漏洞

  1. 查看相关软件的版本号,命令如下:
  2. [root@m01 ~]# rpm -qa openssl openssh bash
  3. openssl-1.0.1e-.el6.x86_64
  4. bash-4.1.-.el6.x86_64
  5. openssh-.3p1-.el6.x86_64
  6.  
  7. 升级已知漏洞的软件版本到最新,命令如下:
  8. yum install openssl openssh bash -y

18、更改ssh服务端远程登录的配置

  1. 修改默认文件路径
  2. vim /etc/ssh/sshd_config
  3.  
  4. 修改的参数
  5. port #端口
  6. PermitEmptyPasswords #是否允许密码为空的用户远程登录
  7. PermitRootLogin #是否允许root登录
  8. UseDNS #指定sshd是否应该对远程主机名进行反向解析,以检查主机名是否与其IP地址真实对应。默认yes.建议改成no ,否则可能会导致SSH连接很慢。
  9. GSSAPIAuthentication no #解决linux之间使用SSH远程连接慢的问题
  10. ListenAddress #监听指定的IP地址
  11.  
  12. 12 批量操作:
  13. sed -ir '13 iPort 55666\nPermitRootLogin no\nPermitEmptyPasswords no\nUseDNS no\nGSSAPIAuthentication no' /etc/ssh/sshd_config

安装linux系统后调优及安全设置的更多相关文章

  1. Linux系统调优及安全设置

    1.关闭SELinux #临时关闭 setenforce 0 #永久关闭 vim /etc/selinux/config SELINUX=disabled 2.设定运行级别为3 #设定运行级别 vim ...

  2. Linux:U盘安装Linux系统

    前天一个同学找我帮忙安装Linux系统,没有光盘,也不想在虚拟机里安装,在此情况下,我就采用U盘方式来安装Linux系统了.又想到还有其他人可能也不会 使用U盘安装系统,这里就作一个简单的介绍. 1. ...

  3. 虚拟机安装Linux系统图文教程

    虚拟机安装Linux系统图文教程 | 浏览:523 | 更新:2014-09-16 15:31 1 2 3 4 5 6 7 分步阅读 Linux系统的安装 工具/原料 VMware 9.0 虚拟机 L ...

  4. 使用VMware10虚拟机安装Linux系统(能力工场)

    作为IT从业人员,我们经常使用到Linux系统,但是实际开发过程我们通常在Windows平台操作,为了满足工作需要,这个时候我们通常在windows平台安装虚拟机,并在其上建立linux系统,这样就极 ...

  5. 安装Linux系统,学习Linux操作基础

    20189230杨静怡 2018-2019-2 <移动平台开发实践>第1周学习总结 安装Linux系统内容总结 一.学习"基于VirtualBox虚拟机安装Ubuntu图文教程& ...

  6. VM虚拟机 安装linux系统

    首先需要下载VMware10 和CentOS-6.4,我这边提供了百度网盘,可供下载链接:https://pan.baidu.com/s/1vrJUK167xnB2JInLH890fw 密码:r4jj ...

  7. 虚拟机virtualBox安装linux系统 xshell远程连接linux

    虚拟机virtualBox安装linux系统 xshell远程连接linux 虚拟机概念: 通过软件, 使用虚拟化技术虚拟出电脑的硬件环境, 充当真实的电脑使用. 常见的虚拟软件: virtualBo ...

  8. 部署虚拟环境安装Linux系统

      目录                                                              准备工作 安装linux系统 重置root管理员密码 源代码编译 R ...

  9. 如何在Windows环境下安装Linux系统虚拟机

    如何在Windows环境下安装Linux系统虚拟机 本篇经验写给想要入门学习C语言的小白们.Windows系统因为使用窗口图形化,操作简单,功能多样,所以我们在Windows环境下可以做到很多,但想要 ...

随机推荐

  1. 宝塔中mysql数据库命名小坑

    今天在通过宝塔新建网站,添加mysql数据库,名字中间有下划线,发现能够创建成功,但是实际链接后,是没有这个数据库的.是宝塔的原因还是liunx服务器的原因? 不支持下划线的数据库名字吗? 比如 bo ...

  2. SpringCloud版本问题

    兴致勃勃地跟随文档创建并配置Eureka Server工程后,启动准备测试,发现报了java.lang.NoSuchMethodError: org.springframework.boot.buil ...

  3. ADO.net中DataTable的应用

     一.思维导图 二.知识点描述 (1)构造函数 DataTable() 不带参数初始化DataTable类的新实例 DataTable(string tableName) 用指定的表名初始化DataT ...

  4. yocto-sumo源码解析(八): ProcessServer

    从前面章节的论述中,我们知道BitBakeServer实际上是一个ProcessServer,什么是ProcessServer不可不了解. 1. 类的声明: 首先这是一个python的多进程包里面的进 ...

  5. maven 添加spring/springmvc依赖项

    <spring.version>4.3.18.RELEASE</spring.version> <dependencies> <!--添加spring.spr ...

  6. Metasploit拿Shell

    进入metasploit系统 msfconsole Nmap端口扫描 nmap –sV IP(或者域名),如果机器设置有防火墙禁ping,可以使用nmap -P0(或者-Pn) –sV IP(或者域名 ...

  7. Python中collections模块的使用

    本文将详细讲解collections模块中的所有类,和每个类中的方法,从源码和性能的角度剖析. 一个模块主要用来干嘛,有哪些类可以使用,看__init__.py就知道 '''This module i ...

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

  9. “秒杀”问题的数据库和SQL设计【转载】

    “秒杀”问题的数据库和SQL设计 APRIL 21ST, 2015 问题的来源 完全不考虑一致性的方案 表结构 方案 存在的问题 保证单用户不会重复购买 解决超卖问题 方案 优化 提高性能了 鱼与熊掌 ...

  10. DataGridView 复选框 操作大全

    DataGridViewCheckBoxColumn dtCheck = new DataGridViewCheckBoxColumn(); dtCheck.DataPropertyName = &q ...