1:  为系统添加操作用户,并授予sudo权限

  1. [root@localhost ~]# groupadd cai
  2. [root@localhost ~]# useradd cai -g cai
  3. [root@localhost ~]# passwd cai
  4. 更改用户 cai 的密码
  5. 新的 密码:
  6. 无效的密码: 过于简单化/系统化
  7. 无效的密码: 过于简单
  8. 重新输入新的 密码:
  9. passwd 所有的身份验证令牌已经成功更新。
  10. [root@localhost ~]# su - cai

sudo的配置文件在/etc/sudoers下面,不过是只读文件。想要修改使用“visudo”命令。

用户名  可登录的终端  具体命令(使用绝对路径,which查看)

cairui    ALL=(ALL)      /usr/sbin/useradd

2:  配置Yum源为国内源(在我的其他博客中专门有一篇介绍,此处不写了)

3:  关闭防火墙(iptables)和Selinux

(1)因为防火墙和selinux的设置很麻烦,而且需要大量的时间去搞,所以索性就关掉。

临时关闭防火墙:(可以查看状态,重启,关闭,打开)

  1. [root@localhost ~]# /etc/init.d/iptables
  2. Usage: iptables {start|stop|reload|restart|condrestart|status|panic|save}

永久关闭防火墙:(关闭开机自启)

  1. [root@localhost ~]# chkconfig iptables off

查看iptables开机状态:

  1. [root@localhost ~]# chkconfig --list | grep iptables
  2. iptables :关闭 :关闭 :关闭 :关闭 :关闭 :关闭 :关闭

(2)关闭selinux

  1. [root@localhost ~]# vim /etc/selinux/config
  2.  
  3. # This file controls the state of SELinux on the system.
  4. # SELINUX= can take one of these three values:
  5. # enforcing - SELinux security policy is enforced.
  6. # permissive - SELinux prints warnings instead of enforcing.
  7. # disabled - No SELinux policy is loaded.
  8. #SELINUX=enforcing
  9. SELINUX=disabled  修改为disabled
  10. # SELINUXTYPE= can take one of these two values:
  11. # targeted - Targeted processes are protected,
  12. # mls - Multi Level Security protection.
  13. SELINUXTYPE=targeted

4:  修改ssh服务的默认配置

修改之前先备份默认的配置:

  1. [root@localhost ~]# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup

再修改

  1. [root@localhost ~]# vim /etc/ssh/sshd_config
  2. # $OpenBSD: sshd_config,v 1.80 // :: djm Exp $
  3.  
  4. # This is the sshd server system-wide configuration file. See
  5. # sshd_config() for more information.
  6.  
  7. # This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
  8.  
  9. # The strategy used for options in the default sshd_config shipped with
  10. # OpenSSH is to specify options with their default value where
  11. # possible, but leave them commented. Uncommented options change a
  12. # default value.
  13.  
  14. #Port
  15. Port 52000 修改Linux默认连接端口
  16. #AddressFamily any
  17. #ListenAddress 0.0.0.0
  18. #ListenAddress ::
  19.  
  20. # Disable legacy (protocol version ) support in the server for new
  21. # installations. In future the default will change to require explicit
  22. # activation of protocol
  23. Protocol
  24.  
  25. # HostKey for protocol version
  26. #HostKey /etc/ssh/ssh_host_key
  27. # HostKeys for protocol version
  28. #HostKey /etc/ssh/ssh_host_rsa_key
  29. #HostKey /etc/ssh/ssh_host_dsa_key
  30.  
  31. # Lifetime and size of ephemeral version server key
  32. #KeyRegenerationInterval 1h
  33. #ServerKeyBits
  34.  
  35. # Logging
  36. # obsoletes QuietMode and FascistLogging
  37. #SyslogFacility AUTH
  38. SyslogFacility AUTHPRIV
  39. #LogLevel INFO
  40.  
  41. # Authentication:
  42.  
  43. #LoginGraceTime 2m
  44. #PermitRootLogin yes
  45. PermitRootLogin no  #不允许root用户登录(因为每个人都知道root能够登录)
  46. #StrictModes yes
  47. #MaxAuthTries
  48. #MaxSessions
  49.  
  50. #RSAAuthentication yes
  51. #PubkeyAuthentication yes
  52. #AuthorizedKeysFile .ssh/authorized_keys
  53. #AuthorizedKeysCommand none
  54. #AuthorizedKeysCommandRunAs nobody
  55.  
  56. # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
  57. #RhostsRSAAuthentication no
  58. # similar for protocol version
  59. #HostbasedAuthentication no
  60. # Change to yes if you don't trust ~/.ssh/known_hosts for
  61. # RhostsRSAAuthentication and HostbasedAuthentication
  62. #IgnoreUserKnownHosts no
  63. # Don't read the user's ~/.rhosts and ~/.shosts files
  64. #IgnoreRhosts yes
  65.  
  66. # To disable tunneled clear text passwords, change to no here!
  67. #PasswordAuthentication yes
  68. #PermitEmptyPasswords no
  69. PasswordAuthentication yes
  70.  
  71. # Change to no to disable s/key passwords
  72. #ChallengeResponseAuthentication yes
  73. ChallengeResponseAuthentication no
  74.  
  75. # Kerberos options
  76. #KerberosAuthentication no
  77. #KerberosOrLocalPasswd yes
  78. #KerberosTicketCleanup yes
  79. #KerberosGetAFSToken no
  80. #KerberosUseKuserok yes
  81.  
  82. # GSSAPI options
  83. #GSSAPIAuthentication no
  84. GSSAPIAuthentication yes
  85. #GSSAPICleanupCredentials yes
  86. GSSAPICleanupCredentials yes
  87. #GSSAPIStrictAcceptorCheck yes
  88. #GSSAPIKeyExchange no
  89.  
  90. # Set this to 'yes' to enable PAM authentication, account processing,
  91. # and session processing. If this is enabled, PAM authentication will
  92. # be allowed through the ChallengeResponseAuthentication and
  93. # PasswordAuthentication. Depending on your PAM configuration,
  94. # PAM authentication via ChallengeResponseAuthentication may bypass
  95. # the setting of "PermitRootLogin without-password".
  96. # If you just want the PAM account and session checks to run without
  97. # PAM authentication, then enable this but set PasswordAuthentication
  98. # and ChallengeResponseAuthentication to 'no'.
  99. #UsePAM no
  100. UsePAM yes
  101.  
  102. # Accept locale-related environment variables
  103. AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
  104. AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
  105. AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
  106. AcceptEnv XMODIFIERS
  107.  
  108. #AllowAgentForwarding yes
  109. #AllowTcpForwarding yes
  110. #GatewayPorts no
  111. #X11Forwarding no
  112. X11Forwarding yes
  113. #X11DisplayOffset
  114. #X11UseLocalhost yes
  115. #PrintMotd yes
  116. #PrintLastLog yes
  117. #TCPKeepAlive yes
  118. #UseLogin no
  119. #UsePrivilegeSeparation yes
  120. #PermitUserEnvironment no
  121. #Compression delayed
  122. #ClientAliveInterval
  123. #ClientAliveCountMax
  124. #ShowPatchLevel no
  125. #UseDNS yes
  126. UseDNS no  #不使用DNS
  127. #PidFile /var/run/sshd.pid
  128. #MaxStartups ::
  129. #PermitTunnel no
  130. #ChrootDirectory none
  131.  
  132. # no default banner path
  133. #Banner none
  134.  
  135. # override default of no subsystems
  136. Subsystem sftp /usr/libexec/openssh/sftp-server
  137.  
  138. # Example of overriding settings on a per-user basis
  139. #Match User anoncvs
  140. # X11Forwarding no
  141. # AllowTcpForwarding no
  142. # ForceCommand cvs server

修改完之后重启:

  1. [root@localhost ~]# /etc/init.d/sshd
  2. 用法: /etc/init.d/sshd {start|stop|restart|reload|force-reload|condrestart|try-restart|status}

5:  系统内核优化

  1. [root@localhost ~]# cat /etc/sysctl.conf
  2. # Kernel sysctl configuration file for Red Hat Linux
  3. #
  4. # For binary values, is disabled, is enabled. See sysctl() and
  5. # sysctl.conf() for more details.
  6. #
  7. # Use '/sbin/sysctl -a' to list all possible parameters.
  8.  
  9. # Controls IP packet forwarding
  10. net.ipv4.ip_forward =
  11.  
  12. # Controls source route verification
  13. net.ipv4.conf.default.rp_filter =
  14.  
  15. # Do not accept source routing
  16. net.ipv4.conf.default.accept_source_route =
  17.  
  18. # Controls the System Request debugging functionality of the kernel
  19. kernel.sysrq =
  20.  
  21. # Controls whether core dumps will append the PID to the core filename.
  22. # Useful for debugging multi-threaded applications.
  23. kernel.core_uses_pid =
  24.  
  25. # Controls the use of TCP syncookies
  26. net.ipv4.tcp_syncookies =
  27.  
  28. # Controls the default maxmimum size of a mesage queue
  29. kernel.msgmnb =
  30.  
  31. # Controls the maximum size of a message, in bytes
  32. kernel.msgmax =
  33.  
  34. # Controls the maximum shared segment size, in bytes
  35. kernel.shmmax =
  36.  
  37. # Controls the maximum number of shared memory segments, in pages
  38. kernel.shmall =
  39.  
  40. # 下面是内核调优参数
  41. net.ipv4.tcp_syn_retries =
  42. net.ipv4.tcp_synack_retries =
  43. net.ipv4.tcp_keepalive_time =
  44. net.ipv4.tcp_keepalive_probes =
  45. net.ipv4.tcp_keepalive_intvl =
  46. net.ipv4.tcp_retries2 =
  47. net.ipv4.tcp_fin_timeout =
  48. net.ipv4.tcp_max_tw_buckets =
  49. net.ipv4.tcp_tw_recycle =
  50. net.ipv4.tcp_tw_reuse =
  51. net.ipv4.tcp_max_orphans =
  52. net.ipv4.tcp_syncookies =
  53. net.ipv4.tcp_max_syn_backlog =
  54. net.ipv4.tcp_wmem =
  55. net.ipv4.tcp_rmem =
  56. net.ipv4.tcp_mem =
  57. net.ipv4.ip_local_port_range =
  58. net.ipv4.ip_conntrack_max =
  59. net.ipv4.netfilter.ip_conntrack_max=
  60. net.ipv4.netfilter.ip_conntrack_tcp_timeout_established=
  61. net.core.somaxconn =
  62. net.core.netdev_max_backlog =
  1. [root@localhost ~]# sysctl -p #配置生效
  2. net.ipv4.ip_forward =
  3. net.ipv4.conf.default.rp_filter =
  4. net.ipv4.conf.default.accept_source_route =
  5. kernel.sysrq =
  6. kernel.core_uses_pid =
  7. net.ipv4.tcp_syncookies =
  8. kernel.msgmnb =
  9. kernel.msgmax =
  10. kernel.shmmax =
  11. kernel.shmall =
  12. net.ipv4.tcp_syn_retries =
  13. net.ipv4.tcp_synack_retries =
  14. net.ipv4.tcp_keepalive_time =
  15. net.ipv4.tcp_keepalive_probes =
  16. net.ipv4.tcp_keepalive_intvl =
  17. net.ipv4.tcp_retries2 =
  18. net.ipv4.tcp_fin_timeout =
  19. net.ipv4.tcp_max_tw_buckets =
  20. net.ipv4.tcp_tw_recycle =
  21. net.ipv4.tcp_tw_reuse =
  22. net.ipv4.tcp_max_orphans =
  23. net.ipv4.tcp_syncookies =
  24. net.ipv4.tcp_max_syn_backlog =
  25. net.ipv4.tcp_wmem =
  26. net.ipv4.tcp_rmem =
  27. net.ipv4.tcp_mem =
  28. net.ipv4.ip_local_port_range =
  29. error: "net.ipv4.ip_conntrack_max" is an unknown key
  30. error: "net.ipv4.netfilter.ip_conntrack_max" is an unknown key
  31. error: "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established" is an unknown key
  32. net.core.somaxconn =
  33. net.core.netdev_max_backlog =

6:  超时设置(timeout)

为了系统的安全,设置无操作超时自动退出登录设置

临时生效:

  1. [root@centos6 ~]# export TMOUT=
  2. [root@centos6 ~]# timed out waiting for input: auto-logout

永久配置生效:

  1. [root@centos6 ~]# echo "export TMOUT=300" >>/etc/profile 实际生产环境 分钟
  2. [root@centos6 ~]# source / etc/profile

7:  加大文件描述符

文件描述符是由无符号整数表示的句柄(一般使用范围0~65535),进程使用它来标识打开的文件。文件描述符与包括相关信息(如文件的打开模式、文件的位置类型、文件的初始类型等)的对象想关联,这些信息称为文件的上下文。

对于内核而言,所有打开的文件都是通过文件描述符引用的。当打开一个现有文件或者创建一个新文件时,内核向进程返回一个文件描述符。

按照惯例,UNIX系统shell使用0-》标准输入,1-》标准输出,2-》标准错误

  1. 查看系统默认的文件描述符大小:
  2. [root@centos6 ~]# ulimit -n
  3.  
  4. [root@centos6 ~]# echo "* - nofile 65535">>/etc/security/limits.conf
  5. 退出重新登录,才会生效
  6. [root@centos6 ~]# ulimit -n

8:  隐藏系统版本消息

  1. [cairui@localhost ~]$ cat /etc/issue
  2. CentOS release 6.8 (Final)
  3. Kernel \r on an \m
  4.  
  5. [cairui@localhost ~]$ cat /etc/issue.net
  6. CentOS release 6.8 (Final)
  7. Kernel \r on an \m
  8.  
  9. 只需要清空上述的文件内容,就可以隐藏信息。

9:  给grub引导菜单加密码保护(因为grub能进入看到root密码)

  1. [root@localhost ~]# /sbin/grub-md5-crypt
  2. Password:
  3. Retype password:
  4. $$kpiKh/$..jTvOdnHGnMsqqs5OWlM/
  5. [root@localhost ~]# vi /etc/grub.conf
  6. [root@localhost ~]# cat /etc/grub.conf
  7. # grub.conf generated by anaconda
  8. #
  9. # Note that you do not have to rerun grub after making changes to this file
  10. # NOTICE: You have a /boot partition. This means that
  11. # all kernel and initrd paths are relative to /boot/, eg.
  12. # root (hd0,)
  13. # kernel /vmlinuz-version ro root=/dev/sda3
  14. # initrd /initrd-[generic-]version.img
  15. #boot=/dev/sda
  16. default=
  17. timeout=
  18. splashimage=(hd0,)/grub/splash.xpm.gz
  19. hiddenmenu
  20. password --md5 $1$hv58gkgk9G995885/JG0orl4m  #后来添加的
  21. title CentOS (2.6.-.el6.x86_64)
  22. root (hd0,)
  23. kernel /vmlinuz-2.6.-.el6.x86_64 ro root=UUID=57e48303-c321-4c12-8ac4-7596c31f55ef rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF- rd_NO_LVM rd_NO_DM rhgb quiet
  24. initrd /initramfs-2.6.-.el6.x86_64.img

10:  调整字符集

  1. [root@centos6 ssh]# echo $LANG
  2. en_US.UTF-
  3. [root@centos6 ssh]# cat /etc/sysconfig/i18n
  4. LANG="en_US.UTF-8"
  5. SYSFONT="latarcyrheb-sun16"
  6. [root@centos6 ssh]# cp /etc/sysconfig/i18n /etc/sysconfig/i18n.2016.12.
  7. [root@centos6 ssh]# sed -i 's#LANG="en_US.UTF-8"#LANG="zh_CN.UTF-8"#g' /etc/sysconfig/i18n
  8. [root@centos6 ssh]# source /etc/sysconfig/i18n
  9. [root@centos6 ssh]# echo $LANG
  10. zh_CN.UTF-

Liunx基础优化配置的更多相关文章

  1. CentOS7.5基础优化与常用配置

    目录 最小化全新安装CentOS7基础优化 配置yum源 安装常用软件 关闭防火墙 关闭SELinux 优化ulimit 历史命令记录改为1万条 把命令提示符改为绿色 添加vim配置文件 添加一个普通 ...

  2. Linu之linux系统基础优化和基本命令

    Linux系统基础优化和基本命令 网络参数设定命令 ifconfig: 查询,设置网卡和ip等参数 ifup,ifdown: 脚本命令,更简单的方式 ip: 符合指令,直接修改上述功能 编辑网卡配置文 ...

  3. Linux实战教学笔记06:Linux系统基础优化

    第六节 Linux系统基础优化 标签(空格分隔):Linux实战教学笔记-陈思齐 第1章 基础环境 第2章 使用网易163镜像做yum源 默认国外的yum源速度很慢,所以换成国内的. 第一步:先备份 ...

  4. 【No.1 Ionic】基础环境配置

    Node 安装 git clone https://github.com/nodejs/node cd node ./configure make sudo make install node -v ...

  5. Centos6.5 64linux系统基础优化(二)

    1  操作的最小化原则 1)安装系统最小化 2)开启程序服务最小化原则 3)操作最小化原则 4)登陆最小化原则;平时没有需求不用root登陆,要用普通登陆. 2  更改ssh服务默认端口及常规配置 # ...

  6. Apache优化配置:修改最大并发连接数

    此文摘自: http://www.365mini.com/page/apache-concurrency-configuration.htm Apache查看连接数和限制当前的连接数 : http:/ ...

  7. Linux基础优化与安全归纳总结

    一名运维工程师在运维岗位上时间久了,就会发现Linux优化的重要性,同时会给运维工作带来很多的便利性.本人逐渐认识到了这一点,所以特意在工作闲暇之余,通过阅读Linux相关书籍及向同事.同行高手咨询, ...

  8. [转帖]关于网络编程中MTU、TCP、UDP优化配置的一些总结

    关于网络编程中MTU.TCP.UDP优化配置的一些总结 https://www.cnblogs.com/maowang1991/archive/2013/04/15/3022955.html 感谢原作 ...

  9. Linux基础优化和安全重点小结

    Linux基础优化和安全重点小结 1.不用root管理,以普通用户的名义通过sudo管理授权(/etc/sudoers)        2.更改默认的ssh服务端口,禁止root用户远程连接,甚至监听 ...

随机推荐

  1. Java-API-Package:org.springframework.web.bind.annotation

    ylbtech-Java-API-Package:org.springframework.web.bind.annotation 1.返回顶部 1. @NonNullApi @NonNullField ...

  2. JPA,EclipseLink 缓存机制学习——树节点搜索问题引发的思考

    最近在项目在使用JPA+EclipseLink 的方式进行开发,其中EclipseLink使用版本为2.5.1.遇到一些缓存方面使用不当造成的问题,从本篇开始逐步学习EclipseLink的缓存机制. ...

  3. [置顶] 都是类型惹的祸——小心unsigned

    正如我们所知道的,编程语句都有很多的基本数据类型,如char,inf,float等等,而在C和C++中还有一个特殊的类型就是无符号数,它由unsigned修饰,如unsigned int等.大家有没想 ...

  4. python3 中 requests 框架

    原文的文件地址:http://blog.csdn.net/shanzhizi/article/details/50903748 一.安装 Requests 通过pip安装 pip install re ...

  5. 01-20Asp.net--Linq语法

    Linq语法--语言集成查询 同Sqlserver语句,但顺序颠倒了. 使用方法: 新建Linq类.dbml结尾的文件 在web窗体源代码中设计表,使用Repeater中转存放: <asp:Re ...

  6. java中常用的时间操作

    最近项目设计时间的转换和计算,长时间没用时间操作了,感觉手有点生,所以在这里记录一下: Date 常用的方法: getTime() .setTime(): SimpleDateFormate 常用的方 ...

  7. JS中,根据div数值判断弹出窗口

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. solr增量数据配置说明

    转帖地址:http://www.blogjava.net/conans/articles/379546.html 以下资料整理自网络,觉的有必要合并在一起,这样方便查看.主要分为两部分,第一部分是对& ...

  9. xUtils 源码解析

    1. 功能介绍 xUtils 一个 Android 公共库框架,主要包括四个部分:View,Db, Http, Bitmap 四个模块. View 模块主要的功能是通过注解绑定 UI,资源,事件. D ...

  10. day17 9.关闭资源与异常处理

    Java程序跟任何外部设备进行连接之后,都要把连接断开,把资源释放掉.Connection是一个重量级资源,Connecton占内存,Connection的获取是比较消耗资源和内存的.finally是 ...