{"id":10,"date":"2015-07-08T15:35:18","date_gmt":"2015-07-08T15:35:18","guid":{"rendered":"http:\/\/virtorbis.virtcompute.com\/?p=10"},"modified":"2015-07-08T16:06:23","modified_gmt":"2015-07-08T16:06:23","slug":"rhel-security-hardening","status":"publish","type":"post","link":"https:\/\/virtorbis.virtcompute.com\/?p=10","title":{"rendered":"RHEL security hardening"},"content":{"rendered":"<p><code>#!\/bin\/bash<br \/>\necho \"RHEL Security hardening script\"<br \/>\necho \"Please check the settings and modify if any required\"<br \/>\necho \"If you do not wish to run the script you can abort in next 10 seconds\"<br \/>\nsleep 15<\/p>\n<p>echo \"1. checking packages which should not be installed:\"<br \/>\nfor package in inetd xinetd ypserv tftp-server telnet-server rsh-serve<br \/>\ndo<br \/>\nif ! rpm -qa | grep $package &gt;&amp; \/etc\/null;<br \/>\nthen<br \/>\necho \"package $package is not installed\"<br \/>\nelse<br \/>\necho \"The $package is installed. Erasing it now.\"<br \/>\nyum erase $package<br \/>\nfi<br \/>\ndone<br \/>\nsleep 2<br \/>\necho \" \"<\/p>\n<p>echo \"2. Linux kernel hardening:\"<br \/>\ncp \/etc\/sysctl.conf \/etc\/sysctl.conf.backup<br \/>\necho \"net.ipv4.ip_forward = 0\" &gt;&gt; \/etc\/sysctl.conf<br \/>\necho \"net.ipv4.conf.default.accept_redirects = 0\" &gt;&gt; \/etc\/sysctl.conf<br \/>\necho \"net.ipv4.conf.all.accept_redirects = 0\" &gt;&gt; \/etc\/sysctl.conf<br \/>\necho \"net.ipv4.conf.all.accept_source_route = 0\" &gt;&gt; \/etc\/sysctl.conf<br \/>\necho \"net.ipv4.tcp_syncookies = 1\" &gt;&gt; \/etc\/sysctl.conf<br \/>\necho \"net.ipv4.conf.all.log_martians = 1\" &gt;&gt; \/etc\/sysctl.conf<br \/>\necho \"net.ipv4.conf.all.rp_filter = 1\" &gt;&gt; \/etc\/sysctl.conf<br \/>\necho \"net.ipv4.conf.default.secure_redirects = 0\" &gt;&gt; \/etc\/sysctl.conf<br \/>\necho \"net.ipv4.conf.all.secure_redirects = 0\" &gt;&gt; \/etc\/sysctl.conf<br \/>\nsleep 2<br \/>\necho \"Changes in \/etc\/sysctl.conf file are done.\"<br \/>\nsleep 1<br \/>\necho \" \"<\/p>\n<p>echo \"3. Checking SElinux settings:\"<br \/>\nx=`cat \/etc\/sysconfig\/selinux | grep ^SELINUX | head -n 1 | awk -F= '{print $2}'`<br \/>\nif [ $x == enforcing ]<br \/>\nthen<br \/>\necho \"SElinux is enabled\"<br \/>\necho \"Changing it to disabled\"<br \/>\nsed -i 's\/^SELINUX=enforcing\/SELINUX=disabled\/' \/etc\/sysconfig\/selinux<br \/>\nelse<br \/>\necho \"SElinux in disabled mode\"<br \/>\nfi<br \/>\necho \" \"<br \/>\nsleep 2<\/p>\n<p>echo \"4. Stopping iptables:\"<br \/>\n\/etc\/init.d\/iptables stop<br \/>\nsleep 2<br \/>\n\/etc\/init.d\/ip6tables stop<br \/>\nsleep 2<br \/>\nchkconfig --level 345 iptables off<br \/>\nsleep 2<br \/>\nchkconfig --level 345 ip6tables off<br \/>\nsleep 2<br \/>\necho \" \"<\/p>\n<p>echo \"6. Enabling SSH settings:\"<br \/>\ncp \/etc\/ssh\/sshd_config \/etc\/ssh\/sshd_config.bkp<br \/>\nsed -i 's\/^#PermitRootLogin yes\/PermitRootLogin yes\/' \/etc\/ssh\/sshd_config<br \/>\necho \" PermitRootLogin yes \"<br \/>\nsed -i 's\/^Protocol 2\/Protocol 2\/' \/etc\/ssh\/sshd_config<br \/>\necho \" Protocol 2 \"<br \/>\nsed -i 's\/^#AllowTcpForwarding yes\/AllowTcpForwarding no\/' \/etc\/ssh\/sshd_config<br \/>\necho \" AllowTcpForwarding no \"<br \/>\nsed -i 's\/^X11Forwarding yes\/X11Forwarding yes\/' \/etc\/ssh\/sshd_config<br \/>\necho \" X11Forwarding no \"<br \/>\nsed -i 's\/^#StrictModes yes\/StrictModes yes\/' \/etc\/ssh\/sshd_config<br \/>\necho \" StrictModes yes \"<br \/>\nsed -i 's\/^#IgnoreRhosts yes\/IgnoreRhosts yes\/' \/etc\/ssh\/sshd_config<br \/>\necho \" IgnoreRhosts yes \"<br \/>\nsed -i 's\/^#HostbasedAuthentication no\/HostbasedAuthentication no\/' \/etc\/ssh\/sshd_config<br \/>\necho \" HostbasedAuthentication no \"<br \/>\nsed -i 's\/^#RhostsRSAAuthentication no\/RhostsRSAAuthentication no\/' \/etc\/ssh\/sshd_config<br \/>\necho \" RhostsRSAAuthentication no \"<br \/>\nsleep 2<br \/>\necho \" \"<\/p>\n<p>echo \"7. Changing different parameters of password aging \/etc\/login\/defs\"<br \/>\necho \" \"<br \/>\nsed -i '\/^PASS_MAX_DAYS\/c\\PASS_MAX_DAYS 90' \/etc\/login.defs<br \/>\nsed -i '\/^PASS_MIN_DAYS\/c\\PASS_MIN_DAYS 7' \/etc\/login.defs<br \/>\nsed -i '\/^PASS_MIN_LEN\/c\\PASS_MIN_LEN 8' \/etc\/login.defs<br \/>\nsed -i '\/^PASS_WARN_AGE\/c\\PASS_WARN_AGE 14' \/etc\/login.defs<br \/>\necho \"Changes in \/etc\/login.defs file are done\"<br \/>\nsleep 2<br \/>\necho \" \"<\/p>\n<p>echo \"8. Verifying empty password accounts:\"<br \/>\nx=`awk -F: '($2 == \"\") {print}' \/etc\/shadow | wc -l`<br \/>\nif [ $x -lt 1 ]<br \/>\nthen<br \/>\necho \"No account is password less\"<br \/>\nelse<br \/>\necho \"At least 1 account is password less.Check the configuration file\"<br \/>\nfi<br \/>\nsleep 2<br \/>\necho \" \"<\/p>\n<p>echo \"9. Checking if No Non-Root Accounts Have UID Set To 0:\"<br \/>\nx=`awk -F: '($3 == \"0\") {print}' \/etc\/passwd | awk -F: '{print $1}'`<br \/>\nif [ $x == root ]<br \/>\nthen<br \/>\necho \"No account other than ROOT has UID 0\"<br \/>\nelse<br \/>\necho \"***** Check the file. More than one accounts have UID 0\"<br \/>\nfi<br \/>\nsleep 2<br \/>\necho \" \"<\/p>\n<p>echo \"10. \/etc\/pam.d\/system-auth settings\"<br \/>\ncp \/etc\/pam.d\/system-auth \/etc\/pam.d\/system-auth.bkp<br \/>\nsed -i 's\/^password required pam_cracklib.so try_first_pass retry=3\/password requisite pam_cracklib.so retry=3 minlen=8 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1 difok=3 try_first_pass\/' \/etc\/pam\/d\/system-atuh<br \/>\nsed -i 's\/^password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok\/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=20\/' \/etc\/pam\/d\/system-auth<br \/>\nsleep 2<br \/>\necho \" settings performed\"<br \/>\nsleep 2<br \/>\necho \" \"<br \/>\necho \" checking for \/etc\/security\/opasswd file\"<br \/>\nif [ -f \/etc\/security\/opasswd ];<br \/>\nthen<br \/>\necho \"File $file exists.\"<br \/>\nelse<br \/>\necho \"File $file does NOT exists.\"<br \/>\ntouch \/etc\/security\/opasswd<br \/>\nfi<br \/>\nsleep 2<\/p>\n<p>echo \"11. Account policy attributes:\"<br \/>\nsed -i 's\/^INACTIVE=-1\/INACTIVE=10' \/etc\/ssh\/sshd_config<br \/>\nsleep 2<br \/>\necho \" \"<\/p>\n<p>echo \"10. Setting 'Banner' and 'Motd'\"<br \/>\necho \" \"<br \/>\necho \"************************************************************************\" &gt; \/etc\/motd<br \/>\necho -e \"* WARNING! By accessing and using this system you are consenting to *\" &gt;&gt; \/etc\/motd<br \/>\necho \"* system monitoring for law enforcement and other purposes. *\" &gt;&gt; \/etc\/motd<br \/>\necho \"* UNAUTHORIZED USE OF THIS COMPUTER SYSTEM MAY SUBJECT YOU TO CRIMINAL *\" &gt;&gt; \/etc\/motd<br \/>\necho \"* PROSECUTION AND PENALTIES. *\" &gt;&gt; \/etc\/motd<br \/>\necho \"************************************************************************\" &gt;&gt; \/etc\/motd<br \/>\ncp \/etc\/motd \/etc\/issue<br \/>\necho \"Banner is set.\"<br \/>\nsleep 2<br \/>\necho \" Settings are performed successfully on the server \"<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash echo &#8220;RHEL Security hardening script&#8221; echo &#8220;Please check the settings and modify if any required&#8221; echo &#8220;If you do not wish to run the script you can abort in next 10 seconds&#8221; sleep 15 echo &#8220;1. checking packages which should not be installed:&#8221; for package in inetd xinetd ypserv tftp-server telnet-server rsh-serve do if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[10,7,9,8],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-rhel","tag-script","tag-security"],"_links":{"self":[{"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10"}],"version-history":[{"count":3,"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":17,"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=\/wp\/v2\/posts\/10\/revisions\/17"}],"wp:attachment":[{"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtorbis.virtcompute.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}