20 recommendations [reprint] to strengthen the security of Linux servers

20 recommendations to strengthen the security of Linux servers

2017-10-19 22:15:01 Author: Linux Edit the source: System Geeks
https://ywnz.com/linuxyffq/99.html

 


With Linux desktops do under normal circumstances in the default configuration is very safe, I agree with this statement (very debatable topic) to some extent. But Linux built-in security model and tools to do really in place, users only need a simple adjustment and a custom Linux server security can be strengthened.

And a malicious user to fight for all the Linux system administrators is a daunting task, this article we will introduce 20 recommendations on how to strengthen the Linux server security, we want to help protect your system.

20 recommendations to strengthen the security of Linux servers

 

1. Physical Security

Disabling external device bootable drive, floppy drive, U-server in the BIOS and BIOS passwords and enable GRUB password to restrict physical access to the system.

 

2. Partition

We can use different partitions to store data dispersed to achieve higher data security, when the event of any disaster, because the data is stored in isolation, the chance of data loss will be minimized.

 

3. Minimize the package to reduce vulnerability

Administrators are advised to avoid non-essential installed in Linux packages from unknown sources and do not use the package to avoid bugs as possible. When a service problem, is likely to spread to other services or even the entire system, so the "non-essential services will not run." This is an iron then.

For CentOS system can use chkconfig to see how it works in the service runlevel 3:

/sbin/chkconfig --list |grep '3:on'

Once found unnecessary services running, you can use the following command to disable:

chkconfig serviceName off

For RPM or DEB package installation services can use yum or apt-get to find out the name of the package and removed with the following command:

yum -y remove package-name

sudo apt-get remove package-name

 

4.查看网络侦听端口

使用 netstat 命令可以看到什么样的网络应用正在侦听哪些端口,找出不必要的程序之后再用上面的方面来处理。

netstat –tulpn

 

5.使用安全的远程连接(SSH)

Telnet 和 rlogin 都使用明文的协议,而且已被证实存在多种已经安全漏洞,SSH 是一种安全的协议,它可以使用加密技术与服务器进行通讯。

非必要时,不要使用 root 账户登录 SSH,要习惯使用 sudo 来切换身份。

SSH 22 端口目标过于明显,建议大家改成一个不常用的高端口并在 vi /etc/ssh/sshd_config 配置文件中至少配置如下选项:

#禁用root登录

PermitRootLogin no

#仅允许特定用户

AllowUsers username

#SSH协议版本

Protocol 2

 

6.保持系统更新

尽量始终保持系统内核、应用补丁及安全修复处在最新状态:

yum updates

yum check-update

 

7.锁定定时任务

cron 可以指定哪些用户可以使用,只需将允许的用户添加到 /etc/cron.allow 或将禁用的用户添加到 /etc/cron.deny 中即可。如果希望禁用所有用户使用任务计划,只需将ALL添加到cron.deny文件当中。

echo ALL >>/etc/cron.deny

 

8.禁用USB存储设备检测

很多时候我们都需要禁用 USB 存储设备以防数据拷出,此时可以创建一个/etc/modprobe.d/no-usb文件并填入如下内容即可禁用 USB 存储设备检测:

install usb-storage /bin/true

 

9.启用SELinux

安全增强型 Linux(SELinux)是在内核中提供的强制访问控制的安全机制。很多网络文章为了方便配置都建议大家禁用 SELinux 功能,我在这里到是建议大家在考虑关闭 SELinux 前应该三思。

SELinux 提供用户三种基本操作模式:

Enforcing:启用和执行机器上的 SELinux 策略(默认配置)

Permissive:在此种模式下,SELinux 不会强制执行系统上的安全策略,只会产生相应日志和警告。Permissive 模式在 SELinux 排错时经常会乃至。

Disabled:禁用 SELinux 功能

如果你想查看当前系统 SELinux 的状态可以使用:

sestatus

如果要从禁用状态启用 SELinux 可以使用:

setenforce enforcing

以上配置只对当前系统状态有用,重启会失效。要一劳永逸开关 SELinux 可以更改其配置文件/etc/selinux/config。

 

10.移除KDE/GNOME桌面

不论你是运行 LAMP 的专属服务器还是其它类型服务器,KDE 或 GNOME 这样 X Window 桌面环境是没多大必要使用的,禁用之后可以提高服务器性能和增强安全性。使用如下命令即可完全卸载:

yum groupremove "X Window System"

 

11.禁用IPv6

IPv6 目前还没有大规模普及,如果你不使用 IPv6 协议,可以在 /etc/sysconfig/network 配置文件中将其禁用。

NETWORKING_IPV6=no

IPV6INIT=no

 

12.限制用户重复使用旧密码

很多用户习惯在强制定期更换密码时重复循环使用以前的密码,这对于服务器管理员来说是一种非常不好的习惯。因此建议大家限制用户重复使用旧密码,该功能可以通过 PAM 来实现。

RHEL/CentOS/Fedora:/etc/pam.d/system-auth

Ubuntu/Debian/Linux Mint:/etc/pam.d/common-password

在上述配置文件中的auth区块添加一行:

auth        sufficient    pam_unix.so likeauth nullok

在password区块添加一行:

password   sufficient    pam_unix.so nullok use_authtok md5 shadow remember=5

配置好后,服务器会禁止使用最近 5 个被使用过的用户密码。

 

13.配置密码过期策略

Linux 中,用户密码是被加密存储到/etc/shadow文件当中的,要配置密码过期的详细信息需要用到change命令。例如要查看某个账户的密码过期日期和时间,可以使用如下命令:

chage -l username

要更改密码过期策略可以使用类似如下命令:

chage -M 60 username

chage -M 60 -m 7 -W 7 username

-M 密码使用最长天数

-m 密码使用最短天数

-W 密码过期提示天数

 

14.手动锁定或解锁账户

在不从系统中移除账户的情况下,对账户进行锁定和解锁是非常有用的一个安全手段。需要锁定一个账户时,可以使用如下命令:

passwd -l accountname

账户锁定同样适用于 root 账户,当某账户被锁定时会增加 (!) 字串,账户解锁时移除 (!) 字串。需要解锁时使用如下命令:

passwd -u accountname

 

15.强制使用强密码

弱密码或用生日密码之类的密码太容易被字典和社会工程学攻破了,所以建议大家打开强密码要求。Linux 中的强密码要求还是使用 PAM 模块,只需编辑/etc/pam.d/system-auth文件:

/lib/security/$ISA/pam_cracklib.so retry=3 minlen=8 lcredit=-1 ucredit=-2 dcredit=-2 ocredit=-1

 

16.启用Iptables

强烈建议大家使用 Iptables 来保护 Linux 服务器安全,Iptables 可以在不同的链上配置不同的规则来处理数据包。

 

17.在Inittab中禁用Ctrl+Alt+Delete

大多数 Linux 发行版中按下「Ctrl+Alt+Delete」时都会重启系统,对于 Linux 生产服务器来说,这几乎是一个白痴设计。如果你希望关闭这个默认重启功能,可以将/etc/inittab配置文件中的如下两千注释掉:

# Trap CTRL-ALT-DELETE

#ca::ctrlaltdel:/sbin/shutdown -t3 -r now

 

18.查看空密码账户

如果系统中存在有权限的空密码账户,就相当于开了一扇门。所以建议大家仔细清查一下:

cat /etc/shadow | awk -F: '($2==""){print $1}'

 

19.忽略ICMP或广播请求

要忽略 ICMP 或广播请求我们可以编辑/etc/sysctl.conf配置文件:

net.ipv4.icmp_echo_ignore_all = 1

net.ipv4.icmp_echo_ignore_broadcasts = 1

配置文件改好之后使用如下命令载入生效:

sysctl –p

 

20.定期审查日志

建议大家将日志文件进行专门的集中存放和处理,这样可以比较有效避免入侵者对日志进行篡改,下面是 Linux 常见的默认日志路径:

/var/log/message – 系统日志或当前活动日志

/var/log/auth.log – 验证日志

/var/log/kern.log – 内核日志

/var/log/cron.log – 任务计划日志

/var/log/maillog – 邮件服务器日志

/var/log/boot.log – 系统启动日志

/var/log/mysqld.log – MySQL 服务器日志

/var/log/secure – 包含验证和授权方面信息

/ Var / log / utmp or / var / log / wtmp - login records file

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11288163.html