Linux Server Hardening Checklist

Checklist :



yum list installed
yum list packageName

or

dpkg --list
dpkg --info packageName

Run each exposed service isolated via VM, Docker, LXC..


yum update

or

apt update && apt upgrade

Use SELinux, Apparmor, Grsecurity when possible.

Feature SELinux AppArmor grsecurity
Automated No (audit2allow and system-config-selinux) Yes (Yast wizard) Yes (auto training / gradm)
Powerful policy setup Yes (very complex) Yes Yes
Default and recommended integration CentOS / RedHat / Debian Suse / OpenSuse / Ubuntu based Any Linux distribution
Training and vendor support Yes (Redhat) Yes (Novell) No (community forum and lists)
Recommend for Advanced user New / advanced user New users
Feature Attaches labels to all files, processes and objects Pathname based system does not require labeling or relabeling filesystem ACLs

passwd -l username
{userName}:{password}:{lastpasswdchanged}:{Minimum_days}:{Maximum_days}:{Warn}:{Inactive}:{Expire}:

Where,


awk -F: '($3 == "0") {print}' /etc/passwd



Check with :

systemctl list-unit-files

This command will list all services installed/deployed.

Print a list of services that lists which runlevels each is configured on or off

systemctl list-unit-files --type=service
systemctl list-dependencies graphical.target

ss -tulpn
netstat -plntu

yum groupremove "X Window System"
yum group remove "$DE_NAME Desktop"


/etc/sysctl.conf file is used to configure kernel parameters at runtime. Linux reads and applies settings from /etc/sysctl.conf at boot time.


Partition Purpose
/usr This is where most executable binaries, the kernel source tree and much documentation go.
/var This is where spool directories such as those for mail and printing go. It also contains the error log directory.
/tmp This is where most temporary data files are stored by apps.
/boot This is where your kernel images and boot loader configuration go.
/home This is where users' home directories go.

If the partitions are in one, a script like this one :

#!/bin/sh
man bash > $(mktemp)
$0

runned with cron or nohup can crash your entire system.

A good way of hardening could be , depending on your IS, to add the following option to /etc/fstab file:

Above options can be set only, if you have a separate partition.

Make sure you create a partition as above with special option set on each partition:



All SUID/SGID bits enabled file can be misused : https://gtfobins.github.io/


If you find a script that is owned by root but is writable by anyone you can add your own malicious code in that script that will escalate your privileges when the script is run as root

# World writable files directories
find / -writable -type d 2>/dev/null
find / -perm -222 -type d 2>/dev/null
find / -perm -o w -type d 2>/dev/null

# World executable folder
find / -perm -o x -type d 2>/dev/null

# World writable and executable folders
find / \( -perm -o w -perm -o x \) -type d 2>/dev/null

Files not owned by any user or group can pose a security problem. Just find them with the following command :

find /dir -xdev \( -nouser -o -nogroup \) -print

IAM / LDAP / SSO ....


Use Kerberos if available : https://docs.redhat.com/en/documentation/red_hat_ansible_automation_platform/2.4/html/automation_controller_administration_guide/assembly-controller-kerberos-authentication



Read your logs using logwatch command (logcheck). You get detailed reporting on unusual items in syslog via email.





Type the following command to disable USB devices on Linux system:

echo 'install usb-storage /bin/true' >> /etc/modprobe.d/disable-usb-storage.conf

You can use same method to disable firewire and thunderbolt modules:

echo "blacklist firewire-core" >> /etc/modprobe.d/firewire.conf
echo "blacklist thunderbolt" >> /etc/modprobe.d/thunderbolt.conf

Once done, users can not quickly copy sensitive data to USB devices or install malware/viruses or backdoor on your Linux based system.




Revision #13
Created 4 September 2024 20:49:55 by Alek
Updated 13 December 2024 09:40:26 by Kaiju