Linux/CentOS服务器安全配置通用指南

2019-01-16 21:00:31于丽

Linux关闭nfs服务及客户端:

service netfs stop chkconfig netfs --level 2345 off service nfslock stop chkconfig nfslock --level 2345 off

如果要恢复某一个服务,可以执行下面操作:

service acpid start && chkconfig acpid on

也可以使用setup工具来设置

3. Linux禁用IPV6

IPv6是为了解决IPv4地址耗尽的问题,但我们的服务器一般用不到它,反而禁用IPv6不仅仅会加快网络,还会有助于减少管理开销和提高安全级别。以下几步在CentOS上完全禁用ipv6。

Linux禁止加载IPv6模块:

让系统不加载ipv6相关模块,这需要修改modprobe相关设定文件,为了管理方便,我们新建设定文件/etc/modprobe.d/ipv6off.conf,内容如下

alias net-pf-10 off options ipv6 disable=1

Linux禁用基于IPv6网络,使之不会被触发启动:

# vi /etc/sysconfig/network NETWORKING_IPV6=no

Linux禁用网卡IPv6设置,使之仅在IPv4模式下运行:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0 IPV6INIT=no IPV6_AUTOCONF=no

Linux关闭ip6tables:

# chkconfig ip6tables off

重启系统,验证是否生效:

# lsmod | grep ipv6 # ifconfig | grep -i inet6

如果没有任何输出就说明IPv6模块已被禁用,否则被启用。

4. Linux iptables规则

启用linux防火墙来禁止非法程序访问。使用iptable的规则来过滤入站、出站和转发的包。我们可以针对来源和目的地址进行特定udp/tcp端口的准许和拒绝访问。

关于防火墙的设置规则请参考博客文章 iptables设置实例。

5. Linux SSH安全

如果有可能,第一件事就是修改ssh的默认端口22,改成如20002这样的较大端口会大幅提高安全系数,降低ssh破解登录的可能性。

创建具备辨识度的应用用户如crm以及系统管理用户sysmgr

# useradd crm -d /apps/crm # passwd crm # useradd sysmgr # passwd sysmgr

5.1 Linux只允许wheel用户组的用户su切换

 

# usermod -G wheel sysmgr # vi /etc/pam.d/su # Uncomment the following line to require a user to be in the "wheel" group. auth required pam_wheel.so use_uid

其他用户切换root,即使输对密码也会提示 su: incorrect password

5.2 Linux登录超时

用户在线5分钟无操作则超时断开连接,在/etc/profile中添加:

export TMOUT=300 readonly TMOUT

5.3 Linux禁止root直接远程登录

# vi /etc/ssh/sshd_config PermitRootLogin no

5.4 Linux限制登录失败次数并锁定