- 1. 关闭SElinuix功能
- This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
1. 关闭SElinuix功能
SELinux是美国国家安全局(NSA)对于强制访问控制的实现,这个功能让系统管理员有爱又恨,我们这里要关闭它,至于安全问题,后面通过其他手段来解决,这也是大多数生产环境的做法,如何非要开启也是可以的。关闭方式如下。
- 修改配置文件,使关闭SELinux永久生效:
[root@Kali ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@Kali ~]# cat /etc/selinux/config
This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
TIPS: 配置完后,可以使用grep命令进行检查。(修改配置文件,需要重启Linux生效。)
[root@Kali ~]# grep "SELINUX=disabled" /etc/selinux/config
SELINUX=disabled
- 通过setenforce命令修改(临时生效)
[root@Kali ~]#setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@Kali ~]#setenforce 0
小结:修改配置文件SElinux后,要想使其生效,必须要重启系统。因此,可配合使用setenforce 0 这个临时使其关闭的命令,这样在重启前后都可以使得selinux关闭生效了,也就是说无须立刻重启服务器了,在生产场景下Linux机器是不能随意重启的。
查看SELinux当前状态的命令是:getenforce
2. 设定运行级别为3(文本模式)
设定运行级别(runlevel)为3,即表示使用文本命令行模式管理Linux,检查命令如下:
[root@Kali ~]# grep 3:initdefault /etc/inittab
id:3:initdefault:
这里的3就是linux默认的运行级别,如果有需求可以将其修改为其他级别。工作中常用3级别,即文本模式。
[root@Kali ~]# runlevel
<==查看当前系统运行级别
N 3
小结:运行级别共6个,切换到别的级别可使用init 0-6 任意其中一个(init 6重启服务器)。
- 关机模式
- 单用户模式
- 没有NFS多用户模式
- 完整多用户模式(默认模式)
- 保留
- 桌面模式
- 重启模式
3. 关闭(防火墙)
在企业环境中,一般只有配置了外网IP的Linux服务器才需要开启防火墙,但即使是有外网IP,对于高并发高流量的业务服务器仍是不能开放的,因为会有较大的性能损失,导致网站访问很慢,这种情况下只能在前端加个更好的硬件防火墙了。
关闭防火墙的具体操作过程如下:
Centos 6 :
[root@Kali ~]# /etc/init.d/iptables stop
#<==临时关闭
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules:
取消开机自动启动:
[root@Kali ~]# chkconfig iptables off
查看防火墙状态:
[root@Kali ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
小结:执行临时关闭的命令后,服务器重启防火墙还会再次启动,要想彻底关闭,还需要取消服务器开机自动启动。
chkconfig iptables off
————————————————————————————————————————————————————-
Centos 7 :systemctl status firewalld.service
#<==查看防火墙状态systemctl stop firewalld.service
#<==关闭防火墙systemctl disable firewalld.service
#<==永久关闭防火墙
4. 字符集调整
GBK: 定长,双字节,非国际标准,企业用得不多。
UTF-8:非定长,1-4字节,广泛支持,企业广泛使用。
中文显示:
[root@Kali ~]# echo 'LANG="zh-CN.UTF-8"' >/etc/sysconfig/i18n
[root@Kali ~]# . /etc/sysconfig/i18n
[root@Kali ~]# echo $LANG
zh-CN.UTF-8
英文显示:
[root@Kali ~]# echo 'LANG="en_US.UTF-8"' >/etc/sysconfig/i18n
[root@Kali ~]# source /etc/sysconfig/i18n
[root@Kali ~]# echo $LANG
en_US.UTF-8
小结:修改好配置文件后,需要使用点 . /etc/sysconfig/i18n或source /etc/sysconfig/i18n命令使其立即生效,如果使用shell客户端连接,还需要修改shell客户端的对应编码。
禁止使用中文
5. 设置闲置账号超时时间
设置闲置账号超时时间的示例命令如下,注意此处的配置仅临时生效。
[root@Kali ~]# export TMOUT=10
[root@Kali ~]#
[root@Kali ~]# timed out waiting for input: auto-logout #<==提示超时退出
TIPS:
为了服务器的安全,我们需要设置一个超时时间,让用户长时间不操作Linux系统的时候
自动登出服务器,工作中。
6. 设置Linux的命令行历史记录数
设置Linux命令行的历史记录示例命令如下,注意此处的配置仅临时生效。
[root@Kali ~]# export HISTSIZE=20
#<=设置仅保留最近的5条命令历史记录
[root@Kali ~]# export HISTFILESIZE=20
#<=命令行命令对应文件的记录数 ~/.bash_history
[root@Kali ~]#history -c
#<=清空命令历史记录
[root@Kali ~]# history -d 98
#<=清除指定的命令行记录,此处把98编号的命令清除
TIPS:
要经常检查命令行历史记录,如发现危险的命令,应当立即清除掉。防止被黑客利用。
小结:
把上述命令放入配置文件,使其可以永久生效。
[root@Kali ~]# export HISTFILESIZE=5
[root@Kali ~]#echo 'export TMOUT=300' >>/etc/profile
[root@Kali ~]# echo 'export HISTSIZE=20' >>/etc/profile
[root@Kali ~]# echo 'export HISTFILESIZE=20' >>/etc/profile
[root@Kali ~]# tail -3 /etc/profile
export TMOUT=300
export HISTSIZE=20
export HISTFILESIZE=20
[root@Kali ~]# source /etc/profile
#<=使得配置文件生效