20 Linux Server Hardening Security Tips
20 Linux Server Hardening Security Tips
Securing 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 Linux box. In this first part of a Linux server security series, I will provide 20 hardening tips for default installation of Linux system.
OR
# dpkg --list # dpkg --info packageName # apt-get remove packageName
Install and Setup XEN Virtualization Software on CentOS Linux 5 How To Setup OpenVZ under RHEL / CentOS Linux
OR
# apt-get update && apt-get upgrade
You can configure Red hat / CentOS / Fedora Linux to send yum package update notification via email. Another option is to apply all security updates via a cron job. Under Debian / Ubuntu Linux you can use apticron to send security notifications.
security extensions to enforce limitations on network and other programs. For example, SELinux provides a variety of security policies for Linux kernel.
#5.1: 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.
Finally, you can also edit the /etc/shadow file in the following fields:
{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. I recommend chage command instead of editing the /etc/shadow by hand:
# chage -M 60 -m 7 -W 7 userName
Recommend readings:
Linux: Force Users To Change Their Passwords Upon First Login Linux turn On / Off password expiration / aging Lock the user password Search for all account without password and lock them Use Linux groups to enhance security
Note you can use passwd command to lock and unlock accounts:
# lock account passwd -l userName # unlocak account passwd -u userName
root:x:0:0:root:/root:/bin/bash
If you see other lines, delete them or make sure other accounts are authorized by you to use UID 0.
OR
nmap -sT -O localhost nmap -sT -O server.example.com
Use iptables to close open ports or stop all unwanted network services using above service and chkconfig commands. #9.2: See Also
Ubuntu / Debian Linux: Services Configuration Tool to Start / Stop System Services. Get Detailed Information About Particular IP address Connections Using netstat Command.
Lighttpd Traffic Shaping: Throttle Connections Per Single IP (Rate Limit). How to: Linux Iptables block common attack. psad: Linux Detect And Block Port Scan Attacks In Real Time.
Create septate 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). Sample /etc/fstab entry to to limit user access on /dev/sda5 (ftp server root directory):
/dev/sda5 /ftpdata ext3 defaults,nosuid,nodev,noexec 1 2
RedHat / Centos Disable IPv6 Networking. Debian / Ubuntu And Other Linux Distros Disable IPv6 Networking. Linux IPv6 Howto - Chapter 19. Security. Linux IPv6 Firewall configuration and scripts are available here.
All SUID/SGID bits enabled file can be misused when the SUID/SGID executable has a security problem or bug. All local or remote user can use such file. It is a good idea to find all such files. Use the find command as follows:
#See all set user id files: find / -perm +4000 # See all group id files find / -perm +2000 # Or combine both in a single command find / \( -perm -4000 -o -perm -2000 \) -print find / -path -prune -o -type f -perm +6000 -ls
You need to investigate each reported file. See reported file man page for further details.
You need to investigate each reported file and either set correct user and group permission or remove it.
You need to investigate each reported file and either assign it to an appropriate user and group or remove it.
#16.1: 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.
---------------------- iptables firewall End --------------------------------------------- SSHD Begin -----------------------Users logging in through sshd: root: 123.xxx.ttt.zzz: 6 times ---------------------- SSHD End --------------------------------------------- Disk Space Begin -----------------------Filesystem /dev/sda3 /dev/sda1 Size 450G 99M Used Avail Use% Mounted on 185G 241G 44% / 35M 60M 37% /boot
See our quick tutorial which explains enabling and using the auditd service.
To encrypt and decrypt files with a password, use gpg command. Linux or UNIX password protect files with openssl and other tools. See how to encrypting directories with ecryptfs. TrueCrypt is free open-source disk encryption software for Windows 7/Vista/XP, Mac OS X and Linux. Howto: Disk and partition encryption in Linux for mobile devices. How to setup encrypted Swap on Linux.
Linux Securing Dovecot IMAPS / POP3S Server with SSL Configuration. Linux Postfix SMTP (Mail Server) SSL Certificate Installations and Configuration. Courier IMAP SSL Server Certificate Installtion and Configuration. Configure Sendmail SSL encryption for sending and receiving email. Enigmail: Encrypted mail with Mozilla thunderbird.
Other Recommendation:
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. How to: Looking for Rootkits. Howto: Enable ExecShield Buffer Overflows Protection. Subscribe to Redhat or Debian Linux security mailing list or RSS feed.
Recommend readings: 1. Red Hat Enterprise Linux - Security Guide. 2. Linux security cookbook- A good collections of security recipes for new Linux admin. 3. Snort 2.1 Intrusion Detection, Second Edition - Good introduction to Snort and Intrusion detection under Linux. 4. Hardening Linux - Hardening Linux identifies many of the risks of running Linux hosts and applications and provides practical examples and methods to minimize those risks. 5. Linux Security HOWTO. In the next part of this series I will discuss how to secure specific applications (such as Proxy, Mail, LAMP, Database) and a few other security tools. Did I miss something? Please add your favorite system security tool or tip in the comments.