Difference between revisions of "20 Linux Server Hardening Security Tips"
Adinugroho (talk | contribs) |
|||
Line 392: | Line 392: | ||
* [[Howto: Linux Dovecot Secure IMAPS / POP3S SSL Server configuration | Linux Securing Dovecot IMAPS / POP3S Server with SSL Configuration]] | * [[Howto: Linux Dovecot Secure IMAPS / POP3S SSL Server configuration | Linux Securing Dovecot IMAPS / POP3S Server with SSL Configuration]] | ||
* [[Linux Postfix SMTP (Mail Server) SSL Certificate Installations and Configuration | Linux Postfix SMTP (Mail Server) SSL Certificate Installations and Configuration]] | * [[Linux Postfix SMTP (Mail Server) SSL Certificate Installations and Configuration | Linux Postfix SMTP (Mail Server) SSL Certificate Installations and Configuration]] | ||
− | * [[Courier IMAP SSL Server Certificate | + | * [[Courier IMAP SSL Server Certificate Installation and Configuration]]. |
* [[Configure Sendmail SSL encryption for sending and receiving email]]. | * [[Configure Sendmail SSL encryption for sending and receiving email]]. | ||
* [[Enigmail: Encrypted mail with Mozilla thunderbird]]. | * [[Enigmail: Encrypted mail with Mozilla thunderbird]]. |
Revision as of 22:59, 17 January 2011
Sumber: http://www.cyberciti.biz/tips/linux-security.html
Mengamankan server Linux anda sangat penting untuk memproteksi data, hak cipta, dan waktu, dari tangan2 jahil para cracker. Sistem administrator bertanggung jawab untuk keamanan linux. Pada bagian ini akan di jelaskan 20 tip untuk mengamankan instalasi linux standard.
Enkripsi Komunikasi Data
Semua data yang di kirimkan melalui jaringan akan terbuka untuk di monitoring. Enkrip data yang dikirim sebisa mungkin dengan password atau menggunakan kunci / key / sertifikat.
- Gunakan scp, ssh, rsync, atau sftp untuk melakukan file transfer. Kita juga dapat me-mount file system di remote server atau home directory kita menggunakan sshfs dan fuse tool.
- GnuPG memungkinkan kita untuk mengenkrip dan sign komunikasi data yang kita lakukan. GnuPG juga mempunyai sistem manajemen key yang baik dan akses ke berbagai directory public key.
- Fugu adalah tampilan grafis dari aplikasi commandline Secure File Transfer (SFTP). SFTP mirip dengan FTP, tapi tidak sama dengan FTP karena semua sesi komunikasi di enkrip. Artinya lebih sukar untuk di tembus oleh pihak ketiga. Aplikasi yang lain adalah FileZilla - sebuah client cross-platform yang mendukung FTP, FTP over SSL/TLS (FTPS), dan SSH File Transfer Protocol (SFTP).
- OpenVPN adalah cost-effective, dan ringan SSL VPN.
- Lighttpd SSL (Secure Server Layer) konfigurasi dan instalasi https
- Apache SSL (Secure Server Layer) konfigurasi dan instalasi https (mod_ssl)
Jangan gunakan FTP, Telnet, dan Rlogin / Rsh
Dalam kondisi jaringan yang normal, maka username, password, dari perintah FTP / telnet / rsh dan proses transfer file akan dengan mudah di tangkap oleh mereka yang berada di jaringan yang sama mengunakan sniffer. Solusi untuk hal ini dapat menggunakan OpenSSH , SFTP, atau FTPS (FTP over SSL), yang menambahkan enkripsi SSL atau TLS ke FTP. di turunan RedHat kita dapat menulis perintah berikut untuk membuang perintah NIS, rsh dan berbagai layanan yang kadaluarsa lainnya:
# yum erase inetd xinetd ypserv tftp-server telnet-server rsh-serve
Minimalkan Software Aplikasi untuk Minimalisasi Kelemahan
Apakah kita membutuhkan berbagai layanan terinstalasi? Hindari instalasi software yang tidak dibutuhkan untuk menghindari kelemahan di software. Gunakan RPM package manager seperti yum atau apt-get dan / atau dpkg untuk melihat semua software yang terinstalasi di sistem. Delete paket yang tidak di inginkan.
# yum list installed # yum list packageName # yum remove packageName
atau
# dpkg --list # dpkg --info packageName # apt-get remove packageName
Satu layanan jaringan per sistem atau per VM Instance
Jalankan layanan jaringan yang berbada di server atau VM instance yang terpisah. Hal ini membatasi jumlah layanan yang dapat di jebol. Sekedar contoh, jika seorang penyerang berhasil mengexploit sebuah software seperti Apache flow, dia akan memperoleh akses ke seluruh server termasuk layanan sepertu MySQL, e-mail server dan masih banyak lagi. Lihat bagaimana cara menginstalasi software virtualisasi:
- Install dan Setup Software Xen Virtualization pada Linux CentOS 5
- Bagaimana Cara Setup OpenVZ pada RHEL / Linux CentOS
Menjaga Kernel Linux dan Software Tetap Up to Date
Menerapkan patch keamanan merupakan bagian penting dari menjaga server Linux. Linux menyediakan semua alat yang diperlukan untuk menjaga sistem anda diperbarui, dan juga memungkinkan untuk upgrade antar versi dengan mudah. Semua pembaruan keamanan harus ditinjau ulang dan diterapkan sesegera mungkin. Sekali lagi, gunakan manajer paket RPM seperti yum dan atau apt-get dan atau dpkg untuk menerapkan semua update keamanan.
# yum update
atau
# apt-get update && apt-get upgrade
Anda dapat mengkonfigurasi Red Hat / CentOS / Fedora Linux untuk mengirim notifikasi update paket yum update email. Pilihan lain adalah dengan menggunakan semua update keamanan melalui cron job. Dalam Debian / Ubuntu Linux Anda dapat menggunakan apticron untuk mengirim notifikasi keamanan.
Menggunakan Linux Security Extension
Linux hadir dengan berbagai patch keamanan yang dapat digunakan untuk menjaga terhadap program yang salah konfigurasi atau yang diambil alih pihak lain. Jika memungkinkan menggunakan SELinux dan ekstensi keamanan Linux lainnya untuk melakukan pembatasan pada jaringan dan program lainnya. Sebagai contoh, SELinux menyediakan berbagai kebijakan keamanan untuk kernel Linux.
SELinux
Saya sangat menyarankan menggunakan SELinux yang menyediakan sebuah Mandatory Access Control (MAC) yang fleksibel. Berdasarkan standar Linux Discretionary Access Control (DAC), sebuah aplikasi atau proses yang berjalan sebagai user (UID atau SUID) memiliki izin pengguna untuk objek seperti file, socket dan proses lainnya. Menjalankan sebuah kernel MAC melindungi sistem dari aplikasi berbahaya atau cacat yang dapat merusak atau menghancurkan sistem. Lihat dokumentasi Redhat resmi yang menjelaskan konfigurasi SELinux.
User Account dan Kebijakan Password Kuat
Gunakan perintah useradd/usermod untuk membuat dan memelihara account pengguna. Pastikan Anda memiliki kebijakan password yang baik dan kuat. Sebagai contoh, password yang baik mencakup minimal 8 karakter dan campuran huruf, angka, karakter khusus, abjad atas, bawah, dan lain-lain. Yang paling penting adalah memilih password yang bisas Anda ingat. Gunakan tool seperti "ripper John" untuk mengetahui password yang lemah pengguna pada server Anda. Konfigurasikan Pam_cracklib.so untuk menegakkan kebijakan password.
Umur Password
Perintah change mengubah jumlah hari antara perubahan password dan tanggal perubahan password terakhir. Informasi ini digunakan oleh sistem untuk menentukan kapan seorang pengguna harus mengubah passwordnya. File /etc/login.defs mendefinisikan konfigurasi situs-khusus untuk deretan shadow password termasuk konfigurasi umur password. Untuk menonaktifkan fitur umur password, masukkan:
chage -M 99999 userName
Untuk mendapatkan informasi password yang telah kadaluarsa, masukkan:
chage -l userName
Akhirnya, Anda juga dapat mengedit /etc/shadow seperti berikut:
{userName}:{password}:{lastpasswdchanged}:{Minimum_days}:{Maximum_days}:{Warn}:{Inactive}:{Expire}:
Dimana,
- Minimum_days: Jumlah minimum dari hari yang diperlukan antara perubahan password, yaitu jumlah hari yang tersisa sebelum pengguna diijinkan mengubah passwordnya.
- Maximum_days: Jumlah maksimum hari password berlaku (setelah itu pengguna akan dipaksa untuk mengubah passwordnya).
- Warn : Jumlah hari sebelum password akan berakhir, pengguna akan diperingatkan bahwa passwordnya harus diubah.
- Expire : Tanggal mutlak saat login tidak mungkin lagi dapat dilakukan.
Sebaiknya untuk tidak mengedit /etc/shadow secara langsung:
# chage -M 60 -m 7 -W 7 userName
Rekomendasi Bacaan:
- 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
Restricting Use of Previous Passwords
You can prevent all users from using or reuse same old passwords under Linux. The pam_unix module parameter remember can be used to configure the number of previous passwords that cannot be reused.
Locking User Accounts After Login Failures
Under Linux you can use the faillog command to display faillog records or to set login failure limits. faillog formats the contents of the failure log from /var/log/faillog database / log file. It also can be used for maintains failure counters and limits.To see failed login attempts, enter:
faillog
To unlock an account after login failures, run:
faillog -r -u userName
Note you can use passwd command to lock and unlock accounts:
# lock account passwd -l userName
# unlocak account passwd -u userName
How Do I Verify No Accounts Have Empty Passwords?
Type the following command
# awk -F: '($2 == "") {print}' /etc/shadow
Lock all empty password accounts:
# passwd -l accountName
Make Sure No Non-Root Accounts Have UID Set To 0
Only root account have UID 0 with full permissions to access the system. Type the following command to display all accounts with UID set to 0:
# awk -F: '($3 == "0") {print}' /etc/passwd
You should only see one line as follows:
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.
Disable root Login
Never ever login as root user. You should use sudo to execute root level commands as and when required. sudo does greatly enhances the security of the system without sharing root password with other users and admins. sudo provides simple auditing and tracking features too.
Physical Server Security
You must protect Linux servers physical console access. Configure the BIOS and disable the booting from external devices such as DVDs / CDs / USB pen. Set BIOS and grub boot loader password to protect these settings. All production boxes must be locked in IDCs (Internet Data Center) and all persons must pass some sort of security checks before accessing your server. See also:
- 9 Tips To Protect Linux Servers Physical Console Access.
Disable Unwanted Services
Disable all unnecessary services and daemons (services that runs in the background). You need to remove all unwanted services from the system start-up. Type the following command to list all services which are started at boot time in run level # 3:
# chkconfig --list | grep '3:on'
To disable service, enter:
# service serviceName stop # chkconfig serviceName off
Mencari Port Network yang Aktif
Gunakan perintah berikut untuk melihat port yang terbuka dan program yang berasosiasi dengan port tersebut:
netstat -tulpn
atau
nmap -sT -O localhost nmap -sT -O server.example.com
Gunakan iptables untuk menutup port tersebut atau matikan layanan jaringan yang tidak di inginkan dan gunakan perintah chkconfig.
See Also
- 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.
Delete X Windows
X Windows on server is not required. There is no reason to run X Windows on your dedicated mail and Apache web server. You can disable and remove X Windows to improve server security and performance. Edit /etc/inittab and set run level to 3. Finally, remove X Windows system, enter:
# yum groupremove "X Window System"
Configure Iptables and TCPWrappers
Iptables is a user space application program that allows you to configure the firewall (Netfilter) provided by the Linux kernel. Use firewall to filter out traffic and allow only necessary traffic. Also use the TCPWrappers a host-based networking ACL system to filter network access to Internet. You can prevent many denial of service attacks with the help of Iptables:
- 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.
Linux Kernel /etc/sysctl.conf Hardening
/etc/sysctl.conf file is used to configure kernel parameters at runtime. Linux reads and applies settings from /etc/sysctl.conf at boot time. Sample /etc/sysctl.conf:
# Turn on execshield kernel.exec-shield=1 kernel.randomize_va_space=1 # Enable IP spoofing protection net.ipv4.conf.all.rp_filter=1 # Disable IP source routing net.ipv4.conf.all.accept_source_route=0 # Ignoring broadcasts request net.ipv4.icmp_echo_ignore_broadcasts=1 net.ipv4.icmp_ignore_bogus_error_messages=1 # Make sure spoofed packets get logged net.ipv4.conf.all.log_martians = 1
Separate Disk Partitions
Separation of the operating system files from user files may result into a better and secure system. Make sure the following filesystems are mounted on separate partitions:
- /usr
- /home
- /var and /var/tmp
- /tmp
Create septate partitions for Apache and FTP server roots. Edit /etc/fstab file and make sure you add the following configuration options:
- noexec - Do not set execution of any binaries on this partition (prevents execution of binaries but allows scripts).
- nodev - Do not allow character or special devices on this partition (prevents use of device files such as zero, sda etc).
- 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
Disk Quotas
Make sure disk quota is enabled for all users. To implement disk quotas, use the following steps:
- Enable quotas per file system by modifying the /etc/fstab file.
- Remount the file system(s).
- Create the quota database files and generate the disk usage table.
- Assign quota policies.
- See implementing disk quotas tutorial for further details.
Turn Off IPv6
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. Currently there are no good tools out which are able to check a system over network for IPv6 security issues. Most Linux distro began enabling IPv6 protocol by default. Crackers can send bad traffic via IPv6 as most admins are not monitoring it. Unless network configuration requires it, disable IPv6 or configure Linux IPv6 firewall:
- 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.
Disable Unwanted SUID and SGID Binaries
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.
World-Writable Files
Anyone can modify world-writable file resulting into a security issue. Use the following command to find all world writable and sticky bits set files:
find /dir -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print
You need to investigate each reported file and either set correct user and group permission or remove it.
Noowner Files
Files not owned by any user or group can pose a security problem. Just find them with the following command which do not belong to a valid user and a valid group
find /dir -xdev \( -nouser -o -nogroup \) -print
You need to investigate each reported file and either assign it to an appropriate user and group or remove it.
Use A Centralized Authentication Service
Without a centralized authentication system, user auth data becomes inconsistent, which may lead into out-of-date credentials and forgotten accounts which should have been deleted in first place. A centralized authentication service allows you maintaining central control over Linux / UNIX account and authentication data. You can keep auth data synchronized between servers. Do not use the NIS service for centralized authentication. Use OpenLDAP for clients and servers.
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.
Logging and Auditing
You need to configure logging and auditing to collect all hacking and cracking attempts. By default syslog stores data in /var/log/ directory. This is also useful to find out software misconfiguration which may open your system to various attacks. See the following logging related articles:
- Linux log file locations
- How to send logs to a remote loghost.
- How do I rotate log files?.
- man pages syslogd, syslog.conf and logrotate.
Monitor Suspicious Log Messages With Logwatch / Logcheck
Read your logs using logwatch or logcheck. These tools make your log reading life easier. You get detailed reporting on unusual items in syslog via email. A sample syslog report:
################### Logwatch 7.3 (03/24/06) #################### Processing Initiated: Fri Oct 30 04:02:03 2009 Date Range Processed: yesterday ( 2009-Oct-29 ) Period is day. Detail Level of Output: 0 Type of Output: unformatted Logfiles for Host: www-52.nixcraft.net.in ################################################################## --------------------- Named Begin ------------------------ **Unmatched Entries** general: info: zone XXXXXX.com/IN: Transfer started.: 3 Time(s) general: info: zone XXXXXX.com/IN: refresh: retry limit for master ttttttttttttttttttt#53 exceeded (source ::#0): 3 Time(s) general: info: zone XXXXXX.com/IN: Transfer started.: 4 Time(s) general: info: zone XXXXXX.com/IN: refresh: retry limit for master ttttttttttttttttttt#53 exceeded (source ::#0): 4 Time(s) ---------------------- Named End ------------------------- --------------------- iptables firewall Begin ------------------------ Logged 87 packets on interface eth0 From 58.y.xxx.ww - 1 packet to tcp(8080) From 59.www.zzz.yyy - 1 packet to tcp(22) From 60.32.nnn.yyy - 2 packets to tcp(45633) From 222.xxx.ttt.zz - 5 packets to tcp(8000,8080,8800) ---------------------- iptables firewall End ------------------------- --------------------- SSHD Begin ------------------------ Users logging in through sshd: root: 123.xxx.ttt.zzz: 6 times ---------------------- SSHD End ------------------------- --------------------- Disk Space Begin ------------------------ Filesystem Size Used Avail Use% Mounted on /dev/sda3 450G 185G 241G 44% / /dev/sda1 99M 35M 60M 37% /boot ---------------------- Disk Space End ------------------------- ###################### Logwatch End ######################### (Note output is truncated) #17.2: System Accounting with auditd
The auditd is provided for system auditing. It is responsible for writing audit records to the disk. During startup, the rules in /etc/audit.rules are read by this daemon. You can open /etc/audit.rules file and make changes such as setup audit file log location and other option. With auditd you can answers the following questions:
- System startup and shutdown events (reboot / halt).
- Date and time of the event.
- User respoisble for the event (such as trying to access /path/to/topsecret.dat file).
- Type of event (edit, access, delete, write, update file & commands).
- Success or failure of the event.
- Records events that Modify date and time.
- Find out who made changes to modify the system's network settings.
- Record events that modify user/group information.
- See who made changes to a file etc.
See our quick tutorial which explains enabling and using the auditd service.
Secure OpenSSH Server
The SSH protocol is recommended for remote login and remote file transfer. However, ssh is open to many attacks. See how to secure OpenSSH server:
- Top 20 OpenSSH Server Best Security Practices.
Install And Use Intrusion Detection System
A network intrusion detection system (NIDS) is an intrusion detection system that tries to detect malicious activity such as denial of service attacks, port scans or even attempts to crack into computers by monitoring network traffic.
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.
Snort is a software for intrusion detection which is capable of performing packet logging and real-time traffic analysis on IP networks.
Protecting Files, Directories and Email
Linux offers excellent protections against unauthorized data access. File permissions and MAC prevent unauthorized access from accessing data. However, permissions set by the Linux are irrelevant if an attacker has physical access to a computer and can simply move the computer's hard drive to another system to copy and analyze the sensitive data. You can easily protect files, and partitons under Linux using the following tools:
- 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.
Mengamankan Email Server
Anda dapat menggunakan SSL certificate dan gpg key untuk mengamankan komunikasi e-mail pada kedua komputer server dan klien:
- Linux Securing Dovecot IMAPS / POP3S Server with SSL Configuration
- Linux Postfix SMTP (Mail Server) SSL Certificate Installations and Configuration
- Courier IMAP SSL Server Certificate Installation and Configuration.
- Configure Sendmail SSL encryption for sending and receiving email.
- Enigmail: Encrypted mail with Mozilla thunderbird.
Rekomendasi Lainnya:
- 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.
Bacaan Rekomendasi
- Red Hat Enterprise Linux - Security Guide.
- Linux security cookbook- Koleksi yang bagus tentag resep keamanan untuk admin Linux baru.
- Snort 2.1 Intrusion Detection, Second Edition - Pengenalan yang bagus untuk Snort dan Intrusion detection pada Linux.
- Hardening Linux - Hardening Linux mengidentifikasi banyak risiko menjalankan host Linux dan aplikasinya dan memberikan contoh-contoh praktis dan metode-metode untuk meminimalkan risiko tersebut.
- Linux Security HOWTO
Pada bagian berikutnya dari seri ini saya akan membahas bagaimana mengamankan aplikasi spesifik (seperti proxy, Mail, LAMP, Database) dan beberapa alat-alat keamanan lainnya.