侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

01-linux基础优化与安全重点总结

2023-12-09 星期六 / 0 评论 / 0 点赞 / 92 阅读 / 7406 字

linux基础优化与安全重点总结 1.不用root 登录,添加普通用户,用sudo授权管理 [root@centos6 ~]#useradd liuwei 添加用户[root@centos6 ~]#

linux基础优化与安全重点总结

1. 不用root 登录,添加普通用户,用sudo授权管理

[root@centos6 ~]#useradd liuwei  添加用户[root@centos6 ~]# vi /etc/sudoers在第98行下面加入root    ALL=(ALL)       ALLliuwei   ALL=(ALL)      /bin/ls ,/bin/cat   //这个是给liuwei这个用户 添加  /bin/ls ,/bin/cat 这两个命令的执行权限

 

2.更改默认的远程连接SSH服务端口和禁止root远程登录

[root@centos6 ~]# vi /etc/ssh/sshd_config#       $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $# This is the sshd server system-wide configuration file.  See# sshd_config(5) for more information.# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin# The strategy used for options in the default sshd_config shipped with# OpenSSH is to specify options with their default value where# possible, but leave them commented.  Uncommented options change a# default value.#下面这是把22端口更改52113Port 52113  #这是不允许远程登录PermitRootLogin no#这个不是不允许空密码PermitEmptyPasswords no#不用DNSUseDNS noGSSAPIAuthentication no

3.定时更新服务器时间

#confab -e进入cronta编辑模式,使用方法同vi输入 0 23 * * * ntpdate asia.pool.ntp.org >> /var/log/ntpdate.log保存退出这样就完成了你的系统到每天23:00去asia.pool.ntp.org 同步时间,并将同步的日志放到/var/log/ntpdate.log三、定时同步时间(在/etc/crontab中添加) * * * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1

 

4.配置yum更新源,从国内更新源下载安装rpm包

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

(若提示wget 命令不存在,则先使用yum install wget命令进行安装操作)

5.关闭selinux关闭iptables(工作场景有wan ip 一般要开,高并发除外)

修改/etc/selinux/config 文件将SELINUX=enforcing改为SELINUX=disabled重启机器即可(注意:生产环境中一般不能随便重启机器)setenforce 更改selinux状态setenforce 0 #设置SELinux 成为permissive模式setenforce 1 设置SELinux 成为enforcing模式getenforce 也可以用这个命令检查/etc/init.d/iptables status 会得到一系列信息,说明防火墙开着。/etc/init.d/iptables stop 关闭防火墙service iptables restart 重启iptables/etc/init.d/iptables restart     重启iptables1.重启后永久性生效:  开启:chkconfig iptables on  关闭:chkconfig iptables off2. 即时生效,重启后失效:  开启:service iptables start  关闭:service iptables stop

6.调整描述符的数量,进程及文件打开都会消耗描述符

[root@centos6 ~]# ulimit –n  查看描述符数量65535怎么调整vim /etc/security/limits.cof把下面一句加到文件的最后一行*              -       nofile          65535或者:ech0 '*              -       nofile          65535'  >> /etc/security/limits.cof

7.定时清理 /var/spool/clientmquene/目录垃圾文件,防止inodes节点占满

8.精简开机启动服务(crod,sshd,network,rsyslog)

for name in ‘chkconfig --list | grep –vE “crond|sshd|network|rsyslog”|awk ‘{print $1}’’;do chkconfig &name off;done

9.linux 内核参数优化 /etc/sysctl.conf,执行sysctl p 生效

 首先打开/etc/sysctl.conf文件,查看如下两行的设置值,这里是:  kernel.shmall = 2097152kernel.shmmax = 4294967295 如果系统默认的配置比这里给出的值大,就不要修改原有配置。同时在/etc/sysctl.conf文件最后,添加以下内容:  fs.file-max = 6553600  kernel.shmmni = 4096  kernel.sem = 250 32000 100 128  net.ipv4.ip_local_port_range = 1024 65000  net.core.rmem_default = 4194304  net.core.rmem_max = 4194304  net.core.wmem_default = 262144  net.core.wmem_max = 262144  这里的“fs.file-max = 6553600”其实是由“fs.file-max = 512 * PROCESSES”得到的,我们指定PROCESSES的值为12800,即为“fs.file-max =512 *12800”。  sysctl.conf文件修改完毕后,接着执行“sysctl -p”使设置生效。

10,更改字符集,支持中文,但是建议还是用英文字符 防止乱码

解决中文问题[liuwei@centos6 ~]$ vi /etc/sysconfig/i18n改成这个LANG=zh_CN.UTF-8[liuwei@centos6 ~]$source /etc/sysconfig/i18n

 

11.锁定关键系统文件

chattr +i  /etc/passwd /etc/group /etc/gshadow /etc/inittab[root@centos6 ~]# chattr +i /etc/passwd /etc/shadow 给这个两个文件加上锁[root@centos6 ~]# useradd liuuseradd: cannot open /etc/passwd[root@centos6 ~]# chattr -i /etc/passwd /etc/shadow     给这个两个文件加解锁[root@centos6 ~]# useradd liu[root@centos6 ~]# chattr -i /etc/passwd /etc/shadow   把这个加锁命令移动一下【因为大家都知道这个是解锁的命令】-bash: /usr/bin/chattr: 没有那个文件或目录[root@centos6 ~]# mv /usr/bin/liuwei /usr/bin/chattr

范例:

# chattr +i .bash_logout     ——>添加一个隐藏的“i”属性,后面再细讲

#lsattr -a             ——>将当前目录的文件或目录下的文件所有属性(包括隐藏属性)列出 

-------------- ./.

-------------- ./..

---i---------- ./.bash_logout

-------------- ./.bash_profile

-------------- ./.bashrc

 

 

12,清空 /etc/issue ,去除系统以及内核版本登录前的版本提示

[root@centos6 ~]# > /etc/issue    隐藏系统的版本信息[root@centos6 ~]#

 

13.实战经验分享(属用性能调优) 
 

Linux 用户线程数限制导致的 java.lang.OutOfMemoryError: unable to create new native thread异常# vi /etc/security/limits.d/90-nproc.conf# Default limit for number of user's processes to prevent# accidental fork bombs.# See rhbz #432903 for reasoning.root soft nproc unlimited* soft nproc 20480

广告 广告

评论区