|
HOW-TO: Harden A Fresh CentOS 5.x Server
|
|
04-24-2010, 01:13 AM
(This post was last modified: 04-24-2010 01:14 AM by Aizal.)
Post: #1
|
|||
|
|||
|
HOW-TO: Harden A Fresh CentOS 5.x Server
#!/bin/sh
set -ve # Script to harden a fresh CentOS 4 or 5 base server install, which installs # any updated packages plus a few useful extras, removes unnecessary # services and setuid bits, and does a little performance tuning. Running it more than once shouldn't hurt anything. # # Run with: Code: wget -O- http://ftp.die.net/pub/harden-centos/harden-centos | sh# Update rpm and yum if possible. (Limit dependencies.) Code: yum -y install rpm yum# Installing useful packages Code: yum -y install joe tcpdump mtr postfix strace zsh gdb perl vixie-cron logrotate# Removing unnecessary daemons and setuid binaries Code: yum -y remove squid krb5-workstation cups at rsh sudo isdn4k-utils sendmail \# Upgrading to latest packages Code: yum -y upgrade# Removing unnecessary setuid bits Code: find / /usr -xdev -type f -perm +04000 | \# Removing unnecessary setgid bits Code: find / /usr -xdev -type f -perm +02000 | \# Setting nosuid,nodev on user partitions, noatime on ext2 and ext3 Code: perl -i~ -p -e 's/(\sext[23]\s+)(defaults)(?=\s)/$1$2,noatime/;next if m#\s/(?:usr|bin)?\s#;next unless m#\s(ext[23]|tmpfs|auto)\s#;s/(?<=\s)(defaults(?:,noatime)?)(?=\s# Adding blackhole routes for bogons Code: [ -f /etc/sysconfig/network-scripts/route-lo ] || cat <<EOF > /etc/sysconfig/network-scripts/route-lo# Add useful settings to /etc/sysctl.conf Code: grep -q kernel.panic /etc/sysctl.conf || cat<<EOF >> /etc/sysctl.conf# Reboot a minute after an Oops Code: kernel.panic = 60# Syncookies make SYN flood attacks ineffective Code: net.ipv4.tcp_syncookies = 1# Ignore bad ICMP Code: net.ipv4.icmp_echo_ignore_broadcasts = 1# Reply to ARPs only from correct interface (required for DSR load-balancers) Code: net.ipv4.conf.all.arp_announce = 2# Allow any following commands to fail without stopping Code: set +e# Shutting down unwanted services Code: for d in acpid rpcidmapd rpcgssd nfslock netfs portmap avahi-daemon avahi-dnsconfd pcscd bluetooth; do# Turn on cron-based auto-updates Code: yum -y install yum-cron# COMPLETED! Thanks to webicero for creating this guides. For more informations and guides about harndening and securing your server, you may also read the guides in SecureCentOS.com ElevatedServers.net "Rise Above The Rest" |
|||
|
« Next Oldest | Next Newest »
|

Search
Member List
Calendar
Help


