40 Linux Server Hardening Security Tips
40 Linux Server Hardening Security Tips
[2019 edition]
last updated August 14, 2019 in CategoriesDebian
Linux, Howto, Linux, Monitoring, RedHat/Fedora Linux, Security, Sys admin, Ubuntu
Linux
S ecuring your Linux server is important to protect your data, intellectual property, and time, from
the hands of crackers (hackers). The system administrator is responsible for security of the Linux
box. In this first part of a Linux server security series, I will provide 40 Linux server hardening tips for
default installation of Linux system.
cyberciti.biz/tips/linux-security.html
1. Use scp, ssh, rsync, or sftp for file transfer. You can also mount remote server file system or
your own home directory using special sshfs and fuse tools.
2. GnuPG allows to encrypt and sign your data and communication, features a versatile key
management system as well as access modules for all kind of public key directories.
3. OpenVPN is a cost-effective, lightweight SSL VPN. Another option is to try out tinc that uses
tunneling and encryption to create a secure private network between hosts on the Internet or
private insecure LAN.
4. Lighttpd SSL (Secure Server Layer) Https Configuration And Installation
5. Apache SSL (Secure Server Layer) Https (mod_ssl) Configuration And Installation
6. How to configure Nginx with free Let’s Encrypt SSL certificate on Debian or Ubuntu Linux
7. SELinux
I strongly recommend using SELinux which provides a flexible Mandatory Access Control (MAC).
Under standard Linux Discretionary Access Control (DAC), an application or process running as a
user (UID or SUID) has the user’s permissions to objects such as files, sockets, and other
processes. Running a MAC kernel protects the system from malicious or flawed applications that
can damage or destroy the system. See the official Redhat documentation which explains SELinux
configuration.
{userName}:{password}:{lastpasswdchanged}:{Minimum_days}:{Maximum_days}:
{Warn}:{Inactive}:{Expire}:
Where,
1. Minimum_days: The minimum number of days required between password changes i.e. the
number of days left before the user is allowed to change his/her password.
2. Maximum_days: The maximum number of days the password is valid (after that user is
forced to change his/her password).
3. Warn : The number of days before password is to expire that user is warned that his/her
password must be changed.
4. Expire : Days since Jan 1, 1970 that account is disabled i.e. an absolute date specifying
when the login may no longer be used.
If you see other lines, delete them or make sure other accounts are authorized by you to use UID 0.
Modern Linux distros with systemd use the systemctl command for the same purpose.
START/STOP/RESTART SERVICE
# journalctl
# journalctl -u network.service
# journalctl -u ssh.service
# journalctl -f
# journalctl -k
Top 32 Nmap Command Examples For Sys/Network Admins for more info. Use iptables to
close open ports or stop all unwanted network services using above service and chkconfig
commands.
update-rc.d like command on Redhat Enterprise / CentOS Linux .
Ubuntu / Debian Linux: Services Configuration Tool to Start / Stop System Services .
Get Detailed Information About Particular IP address Connections Using netstat Command.
# Turn on execshield
kernel.exec-shield=1
kernel.randomize_va_space=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.all.accept_source_route=0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.icmp_ignore_bogus_error_messages=1
net.ipv4.conf.all.log_martians = 1
/usr
/home
/var and /var/tmp
/tmp
Create separate partitions for Apache and FTP server roots. Edit /etc/fstab file and make sure you
add the following configuration options:
1. noexec – Do not set execution of any binaries on this partition (prevents execution of
binaries but allows scripts).
2. nodev – Do not allow character or special devices on this partition (prevents use of device
files such as zero, sda etc).
3. nosuid – Do not set SUID/SGID access on this partition (prevent the setuid bit).
23. Turn Off IPv6 only if you are NOT using it on Linux
Internet Protocol version 6 (IPv6) provides a new Internet layer of the TCP/IP protocol suite that
replaces Internet Protocol version 4 (IPv4) and provides many benefits. If you are NOT using IPv6
disable it:
You need to investigate each reported file. See reported file man page for further details.
28. Kerberos
Kerberos performs authentication as a trusted third party authentication service by using
cryptographic shared secret under the assumption that packets traveling along the insecure network
can be read, modified, and inserted. Kerberos builds on symmetric-key cryptography and requires a
key distribution center. You can make remote login, remote copy, secure inter-system file copying
and other high-risk tasks safer and more controllable using Kerberos. So, when users authenticate
to network services using Kerberos, unauthorized users attempting to gather passwords by
monitoring network traffic are effectively thwarted. See how to setup and use Kerberos.
( 2009-Oct-29 )
Period is day.
##################################################################
**Unmatched Entries**
123.xxx.ttt.zzz: 6 times
See our quick tutorial which explains enabling and using the auditd service.
It is a good practice to deploy any integrity checking software before system goes online in a
production environment. If possible install AIDE software before the system is connected to any
network. AIDE is a host-based intrusion detection system (HIDS) it can monitor and analyses the
internals of a computing system. I recommended that you install and use rkhunter root kit detection
software too.
Debian / Ubuntu Linux Install Advanced Intrusion Detection Environment (AIDE) Software
psad: Linux Detect And Block Port Scan Attacks In Real Time
ServerTokens Prod
ServerSignature Off
TraceEnable Off
39. Backups
It cannot be stressed enough how important it is to make a backup of your Linux system. A proper
offsite backup allows you to recover from cracked server i.e. an intrusion. The traditional UNIX
backup programs are dump and restore are also recommended. You must set up encrypted backups
to external storage such as NAS server or FreeNAS server or use cloud computing service such as
AWS:
Debian / Ubuntu Linux Install and Configure Remote Filesystem Snapshot with rsnapshot
Incremental Backup Utility
How To Set Red hat / CentOS Linux Remote Backup / Snapshot Server
How To Back Up a Web Server
How To Use rsync Command To Backup Directory Under Linux