{"id":12029,"date":"2019-03-21T03:49:23","date_gmt":"2019-03-21T03:49:23","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12029"},"modified":"2019-03-21T03:49:23","modified_gmt":"2019-03-21T03:49:23","slug":"the-mega-guide-to-harden-and-secure-centos-7","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/21\/the-mega-guide-to-harden-and-secure-centos-7\/","title":{"rendered":"The Mega Guide To Harden and Secure CentOS 7"},"content":{"rendered":"<p>This tutorial only covers general security tips for\u00a0<strong>CentOS 7<\/strong>\u00a0which can be used to harden the system. The checklist tips are intended to be used mostly on various types of bare-metal servers or on machines (physical or virtual) that provides network services.<\/p>\n<div id=\"attachment_20612\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/05\/CentOS-7-Security-Hardening-Guide.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-20612\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/05\/CentOS-7-Security-Hardening-Guide.png\" alt=\"Security and Hardening of CentOS 7\" width=\"720\" height=\"345\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Security and Hardening of CentOS 7<\/p>\n<\/div>\n<p>However, some of tips can be successfully applied on general purpose machines too, such as Desktops, Laptops and card-sized single-board computers (<strong>Raspberry Pi<\/strong>).<\/p>\n<h4>Requirements<\/h4>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/centos-7-installation\/\" target=\"_blank\" rel=\"noopener\">CentOS 7 Minimal Installation<\/a><\/li>\n<\/ol>\n<h3>1. Physical Protection<\/h3>\n<p>Lock down your server rooms access, use racks locking and video surveillance. Take into consideration that any physical access to server rooms can expose your machine to serious security issues.<\/p>\n<p><strong>BIOS<\/strong>\u00a0passwords can be changed by resetting jumpers on the motherboard or by disconnecting the CMOS battery. Also, an intruder can steal the hard disks or directly attach new hard disks to the motherboard interfaces (SATA, SCSI etc), boot up with a Linux live distro and clone or copy data without leaving any software trace.<\/p>\n<h3>2. Reduce Spying Impact<\/h3>\n<p>In case of highly sensitive data you should probably use advanced physical protection such as placing and locking the server into a\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Faraday_cage\" target=\"_blank\" rel=\"nofollow noopener\">Faraday Cage<\/a>\u00a0or use a military\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Tempest_%28codename%29\" target=\"_blank\" rel=\"nofollow noopener\">TEMPEST<\/a>\u00a0solution in order to minimize the impact of spying the system via radio or electrical leaking emanations.<\/p>\n<h3>3. Secure BIOS\/UEFI<\/h3>\n<p>Start the process of harden your machine by securing\u00a0<strong>BIOS\/UEFI<\/strong>\u00a0settings, especially set a\u00a0<strong>BIOS\/UEFI<\/strong>\u00a0password and disable boot media devices (CD, DVD, disable USB support) in order to prevent an unauthorized users from modifying the system BIOS settings or altering the boot device priority and booting the machine from an alternate medium.<\/p>\n<p>In order to apply this type of changes to your machine you need to consult the motherboard manufacturer manual for specific instructions.<\/p>\n<h3>4. Secure Boot Loader<\/h3>\n<p>Set a\u00a0<strong>GRUB<\/strong>\u00a0password in order to prevent malicious users to tamper with kernel boot sequence or runlevels, edit kernel parameters or start the system into single user mode in order to harm your system and\u00a0<a href=\"https:\/\/www.tecmint.com\/reset-forgotten-root-password-in-centos-7-rhel-7\/\" target=\"_blank\" rel=\"noopener\">reset root password<\/a>\u00a0to gain privileged control.<\/p>\n<h3>5. Use Separate Disk Partitions<\/h3>\n<p>When installing\u00a0<strong>CentOS<\/strong>\u00a0on systems intended as production servers use dedicated partitions or dedicated hard disks for the following parts of the system:<\/p>\n<pre>\/(root) \r\n\/boot  \r\n\/home  \r\n\/tmp \r\n\/var \r\n<\/pre>\n<h3>6. Use LVM and RAID for Redundancy and File System Growth<\/h3>\n<p>The\u00a0<strong>\/var<\/strong>\u00a0partition is the place where log messages are written to disk. This part of the system can exponential grow in size on heavily traffic servers which expose network services such as web servers or file servers.<\/p>\n<p>Thus, use a large partition for\u00a0<strong>\/var<\/strong>\u00a0or consider on setting up this partition using logical volumes (<strong>LVM<\/strong>) or combine several physical disks into one larger virtual RAID 0 device to sustain large amounts of data. For data redundancy consider on using LVM layout on top of\u00a0<strong>RAID 1<\/strong>\u00a0level.<\/p>\n<p>For setting up LVM or RAID on the disks, follow our useful guides:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/create-lvm-storage-in-linux\/\" target=\"_blank\" rel=\"noopener\">Setup Disk Storage with LVM in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/manage-and-create-lvm-parition-using-vgcreate-lvcreate-and-lvextend\/\" target=\"_blank\" rel=\"noopener\">Create LVM Disks Using vgcreate, lvcreate and lvextend<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/combine-partitions-into-one-in-linux-using-mhddfs\/\" target=\"_blank\" rel=\"noopener\">Combine Several Disks into One Large Virtual Storage<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/create-raid1-in-linux\/\" target=\"_blank\" rel=\"noopener\">Create RAID 1 Using Two Disks in Linux<\/a><\/li>\n<\/ol>\n<h3>7. Modify fstab Options to Secure Data Partitions<\/h3>\n<p>Separate partitions intended for storing data and prevent the execution of programs, device files or\u00a0<strong>setuid<\/strong>\u00a0bit on these type of partitions by adding the following options to\u00a0<strong>fstab<\/strong>\u00a0file as illustrated on the below excerpt:<\/p>\n<pre>\/dev\/sda5 \t \/nas          ext4    defaults,<strong>nosuid,nodev,noexec<\/strong> 1 2\r\n<\/pre>\n<p>To prevent privilege-escalation and arbitrary script execution create a separate partition for\u00a0<strong>\/tmp<\/strong>\u00a0and mount it as\u00a0<strong>nosuid<\/strong>,\u00a0<strong>nodev<\/strong>\u00a0and\u00a0<strong>noexec<\/strong>.<\/p>\n<pre>\/dev\/sda6  \t\/tmp         ext4    defaults,<strong>nosuid,nodev,noexec<\/strong> 0 0\r\n<\/pre>\n<h3>8. Encrypt the Hard Disks at block level with LUKS<\/h3>\n<p>In order to protect sensitive data snooping in case of physical access to machine hard drives. I suggest you to learn how to encrypt disk by reading our article\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-hard-disk-encryption-using-luks\/\" target=\"_blank\" rel=\"noopener\">Linux Hard Disk Data Encryption with LUKS<\/a>.<\/p>\n<h3>9. Use PGP and Public-Key Cryptography<\/h3>\n<p>In order to encrypt disks, use PGP and Public-Key Cryptography or openssl command to encrypt and decrypt sensitive files with a password as shown in this article\u00a0<a href=\"https:\/\/www.tecmint.com\/rhcsa-exam-create-format-resize-delete-and-encrypt-partitions-in-linux\/\" target=\"_blank\" rel=\"noopener\">Configure Encrypted Linux System Storage<\/a>.<\/p>\n<h3>10. Install Only the Minimum Amount of Packages Required<\/h3>\n<p>Avoid installing unimportant or unnecessary programs, applications or services to avoid package vulnerabilities. This can decrease the risk that the compromise of a piece of software may lead to compromise other applications, parts of the system or even file systems, finally resulting in data corruption or data loss.<\/p>\n<h3>11. Update the system frequently<\/h3>\n<p>Update the system regularly. Keep Linux kernel in sync with the latest security patches and all the installed software up-to-date with the latest versions by issuing the below command:<\/p>\n<pre># yum update\r\n<\/pre>\n<h3>12. Disable Ctrl+Alt+Del<\/h3>\n<p>In order to prevent users to reboot the server once they have physical access to keyboard or via a Remote Console Application or a virtualized console (<strong>KVM<\/strong>, Virtualizing software interface) you should disable\u00a0<code>Ctrl+Alt+Del<\/code>\u00a0key sequence by executing the below command.<\/p>\n<pre># systemctl mask ctrl-alt-del.target \r\n<\/pre>\n<h3>13. Remove Unnecessary Software Packages<\/h3>\n<p>Install minimal software required for your machine. Never install extra programs or services. Install packages only from trusted or official repositories. Use minimal installation of the system in case the machine is destined to run its entire live as a server.<\/p>\n<p>Verify installed packages using one of the following commands:<\/p>\n<pre># rpm -qa<\/pre>\n<p>Make a local list of all installed packages.<\/p>\n<pre># yum list installed &gt;&gt; installed.txt\r\n<\/pre>\n<p>Consult the list for useless software and delete a package by issuing the below command:<\/p>\n<pre># yum remove package_name\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/remove-unwanted-services-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">Disable and Remove Unwanted Packages on Minimal Installation of CentOS 7<\/a>.<\/p>\n<h3>14. Restart systemd services after daemon updates<\/h3>\n<p>Use the below command example to restart a systemd service in order to apply new updates.<\/p>\n<pre># systemctl restart httpd.service\r\n<\/pre>\n<h3>15. Remove Unneeded Services<\/h3>\n<p>Identify the services that are listening on specific ports using the following command.<\/p>\n<pre># ss -tulpn\r\n<\/pre>\n<p>To list all installed services with their output status issue the below command:<\/p>\n<pre># systemctl list-units -t service\r\n<\/pre>\n<p>For instance,\u00a0<strong>CentOS 7<\/strong>\u00a0default minimal installation comes with Postfix daemon installed by default which runs by the name of master under port\u00a0<strong>25<\/strong>. Remove Postfix network service in case your machine will not be used as a mail server.<\/p>\n<pre># yum remove postfix\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/remove-unwanted-services-from-linux\/\" target=\"_blank\" rel=\"noopener\">Stop and Disable Unwanted Services in CentOS 7<\/a>.<\/p>\n<h3>16. Encrypt Transmitted Data<\/h3>\n<p>Do not use unsecure protocols for remote access or file transfer such as\u00a0<strong>Telnet<\/strong>,\u00a0<strong>FTP<\/strong>\u00a0or other plain text high protocols such as SMTP, HTTP, NFS or SMB which, by default, does not encrypt the authentication sessions or sent data.<\/p>\n<p>Use only\u00a0<a href=\"https:\/\/www.tecmint.com\/sftp-command-examples\/\" target=\"_blank\" rel=\"noopener\">sftp<\/a>,\u00a0<a href=\"https:\/\/www.tecmint.com\/scp-commands-examples\/\" target=\"_blank\" rel=\"noopener\">scp<\/a>\u00a0for file transfers and SSH or VNC over SSH tunnels for remote console connections or GUI access.<\/p>\n<p>In order to tunnel a VNC console via SSH use the below example which forwards the VNC port 5901 from the remote machine to your local machine:<\/p>\n<pre># ssh -L 5902:localhost:5901 remote_machine\r\n<\/pre>\n<p>On local machine run the below command in order to virtual connect to the remote endpoint.<\/p>\n<pre># vncviewer localhost:5902\r\n<\/pre>\n<h3>17. Network Port Scanning<\/h3>\n<p>Conduct external port checks using the nmap tool from a remote system over the LAN. This type of scanning can be used to verify network vulnerabilities or test the firewall rules.<\/p>\n<pre># nmap -sT -O 192.168.1.10\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/nmap-command-examples\/\" target=\"_blank\" rel=\"noopener\">Learn How to Use Nmap with these 29 Examples<\/a>.<\/p>\n<h3>18. Packet-filtering Firewall<\/h3>\n<p>Use\u00a0<strong>firewalld<\/strong>\u00a0utility to protect the system ports, open or close specific services ports, especially well-known ports (&lt;1024).<\/p>\n<p>Install, start, enable and list the firewall rules by issuing the below commands:<\/p>\n<pre># yum install firewalld\r\n# systemctl start firewalld.service\r\n# systemctl enable firewalld.service\r\n# firewall-cmd --list-all\r\n<\/pre>\n<h3>19. Inspect Protocol Packets with tcpdump<\/h3>\n<p>Use\u00a0<strong>tcpdump<\/strong>\u00a0utility in order to sniff network packets locally and inspect their content for suspicious traffic (source-destination ports, tcp\/ip protocols, layer two traffic, unusual ARP requests).<\/p>\n<p>For a better analysis of the\u00a0<strong>tcpdump<\/strong>\u00a0captured file use a more advanced program such as\u00a0<strong>Wireshark<\/strong>.<\/p>\n<pre># tcpdump -i eno16777736 -w tcpdump.pcap\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/12-tcpdump-commands-a-network-sniffer-tool\/\" target=\"_blank\" rel=\"noopener\">12 tcpdump Command Examples<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/wireshark-network-protocol-analyzer-tool-for-rhelcentosfedora\/\" target=\"_blank\" rel=\"noopener\">Analyze Network Using Wireshark Tool<\/a>.<\/p>\n<h3>20. Prevent DNS Attacks<\/h3>\n<p>Inspect the contents of your resolver, typically\u00a0<strong>\/etc\/resolv.conf<\/strong>\u00a0file, which defines the IP address of the DNS servers it should use to query for domain names, in order to avoid man-in-the-middle attacks, unnecessary traffic for root DNS servers, spoof or create a DOS attack.<\/p>\n<p>This is just the first part. On the next part we\u2019ll discuss other security tips for\u00a0<strong>CentOS 7<\/strong>.<\/p>\n<p>Continuing the previous tutorial on\u00a0<a href=\"https:\/\/www.tecmint.com\/security-and-hardening-centos-7-guide\/\" target=\"_blank\" rel=\"noopener\">how to secure CentOS 7<\/a>, in this article we\u2019ll discuss other security tips that will be presented on the below checklist.<\/p>\n<div id=\"attachment_20617\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/05\/centos-7-hardening-and-security-guide.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-20617\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/05\/centos-7-hardening-and-security-guide.png\" alt=\"Hardening and Securing of CentOS 7 Server\" width=\"720\" height=\"345\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Hardening and Securing of CentOS 7 Server<\/p>\n<\/div>\n<h4>Requirements<\/h4>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/security-and-hardening-centos-7-guide\/\" target=\"_blank\" rel=\"noopener\">The Mega Guide To Harden and Secure CentOS 7 \u2013 Part 1<\/a><\/li>\n<\/ol>\n<h3>21. Disable Useless SUID and SGID Commands<\/h3>\n<p>If the\u00a0<strong>setuid<\/strong>\u00a0and\u00a0<strong>setgid<\/strong>\u00a0bits are set on binary programs, these commands can run tasks with other user or group rights, such as\u00a0<strong>root<\/strong>\u00a0privileges which can expose seriously security issues.<\/p>\n<p>Often, buffer overrun attacks can exploit such executables binaries to run unauthorized code with the rights of a root power user.<\/p>\n<pre># find \/  -path \/proc -prune -o -type f \\( -perm -4000 -o -perm -2000 \\) -exec ls -l {} \\;\r\n<\/pre>\n<p>To unset the\u00a0<strong>setuid<\/strong>\u00a0bit execute the below command:<\/p>\n<pre># chmod u-s \/path\/to\/binary_file\r\n<\/pre>\n<p><center><ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-2601749019656699\" data-ad-slot=\"5590002574\" data-ad-format=\"auto\" data-adsbygoogle-status=\"done\"><ins id=\"aswift_4_expand\"><ins id=\"aswift_4_anchor\"><iframe id=\"aswift_4\" name=\"aswift_4\" width=\"780\" height=\"90\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\" data-mce-fragment=\"1\"><\/iframe><\/ins><\/ins><\/ins><\/center>To unset the setgid bit run the below command:<\/p>\n<pre># chmod g-s \/path\/to\/binary_file\r\n<\/pre>\n<h3>22. Check for Unowned Files and Directories<\/h3>\n<p>Files or directories not owned by a valid account must be deleted or assigned with permissions from a user and group.<\/p>\n<p>Issue the below command to list files or directories with no user and group.<\/p>\n<pre># find \/ -nouser -o -nogroup -exec ls -l {} \\;\r\n<\/pre>\n<h3>23. List World-Writeable Files<\/h3>\n<p>Keeping word-writable file on the system can be dangerous due to the fact that anyone can modify them. Execute the below command in order to display word-writeable files, except\u00a0<strong>Symlinks<\/strong>, which are always world-writeable.<\/p>\n<pre># find \/ -path \/proc -prune -o -perm -2 ! -type l \u2013ls\r\n<\/pre>\n<h3>24. Create Strong Passwords<\/h3>\n<p>Create a password of minimum of eight characters. The password must contain digits, special characters and uppercase letters. Use\u00a0<strong>pwmake<\/strong>\u00a0to generate a password of 128 bits from\u00a0<strong>\/dev\/urandom<\/strong>\u00a0file.<\/p>\n<pre># pwmake 128\r\n<\/pre>\n<h3>25. Apply Strong Password Policy<\/h3>\n<p>Force the system to use strong passwords by adding the below line in\u00a0<strong>\/etc\/pam.d\/passwd<\/strong>\u00a0file.<\/p>\n<pre>password required pam_pwquality.so retry=3\r\n<\/pre>\n<p>Adding the above line, the password entered cannot contain more than\u00a0<strong>3<\/strong>\u00a0characters in a monotonic sequence, such as\u00a0<strong>abcd<\/strong>, and more than 3 identical consecutive characters, such as\u00a0<strong>1111<\/strong>.<\/p>\n<p>To force users to use a password with a minimum length of\u00a0<strong>8<\/strong>\u00a0characters, including all classes of characters, strength-check for character sequences and consecutive characters add the following lines to the\u00a0<strong>\/etc\/security\/pwquality.conf<\/strong>\u00a0file.<\/p>\n<pre>minlen = 8\r\nminclass = 4\r\nmaxsequence = 3\r\nmaxrepeat = 3<\/pre>\n<h3>26. Use Password Aging<\/h3>\n<p>The\u00a0<strong>chage<\/strong>\u00a0command can be used for user password aging. To set a user\u2019s password to expire in\u00a0<strong>45<\/strong>\u00a0days, use the following command:<\/p>\n<pre># chage -M 45 username\r\n<\/pre>\n<p>To disable password expiration time use the command:<\/p>\n<pre># chage -M -1 username\r\n<\/pre>\n<p>Force immediate password expiration (user must change password on next login) by running the following command:<\/p>\n<pre># chage -d 0 username\r\n<\/pre>\n<h3>27. Lock Accounts<\/h3>\n<p>User accounts can be locked by executing the\u00a0<strong>passwd<\/strong>\u00a0or\u00a0<a href=\"https:\/\/www.tecmint.com\/usermod-command-examples\/\" target=\"_blank\" rel=\"noopener\">usermod<\/a>\u00a0command:<\/p>\n<pre># passwd -l username\r\n# usermod -L username<\/pre>\n<p>To unlock accounts use the\u00a0<code>-u<\/code>\u00a0option for\u00a0<strong>passwd<\/strong>\u00a0command and\u00a0<code>-U<\/code>\u00a0option for\u00a0<strong>usermod<\/strong>.<\/p>\n<h3>28. Prevent Accounts Shell Access<\/h3>\n<p>To prevent a system account (ordinary account or service account) to gain access to bash shell, change root shell to\u00a0<strong>\/usr\/sbin\/nologin<\/strong>\u00a0or\u00a0<strong>\/bin\/false<\/strong>\u00a0in the\u00a0<strong>\/etc\/passwd<\/strong>\u00a0file by issuing the command below:<\/p>\n<pre># usermod -s \/bin\/false username\r\n<\/pre>\n<p>To change the shell when creating a new user issue the following command:<\/p>\n<pre># useradd -s \/usr\/sbin\/nologin username\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/add-users-in-linux\/\" target=\"_blank\" rel=\"noopener\">Learn 15 Examples of \u201cuseradd\u201d Command in Linux<\/a><\/p>\n<h3>29. Lock Virtual User Console with vlock<\/h3>\n<p><strong>vlock<\/strong>\u00a0is a program used for locking one multiple sessions on Linux console. Install the program and start locking your terminal session by running the below commands:<\/p>\n<pre># yum install vlock\r\n# vlock\r\n<\/pre>\n<h3>30. Use a Centralized System to Manage Accounts and Authentication<\/h3>\n<p>Using a centralized authentication system can greatly simplify account management and control. Services that can offer this type of account management are: IPA Server, LDAP, Kerberos, Microsoft Active Directory, Nis, Samba ADS or Winbind.<\/p>\n<p>Some of these services are by default highly secured with cryptographic protocols and symmetric-key cryptography, such as Kerberos.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/setting-up-nfs-server-with-kerberos-based-authentication\/\" target=\"_blank\" rel=\"noopener\">Setup NFS Server with Kerberos-based User Authentication in Linux<\/a><\/p>\n<h3>31. Force Read-Only Mounting of USB Media<\/h3>\n<p>Using\u00a0<strong>blockdev<\/strong>\u00a0utility you can force all removable media to be mounted as read-only. For instance, create a new\u00a0<strong>udev<\/strong>\u00a0configuration file named\u00a0<strong>80-readonly-usb.rules<\/strong>\u00a0in the\u00a0<strong>\/etc\/udev\/rules.d\/<\/strong>\u00a0directory with the following content:<\/p>\n<pre>SUBSYSTEM==\"block\",ATTRS{removable}==\"1\",RUN{program}=\"\/sbin\/blockdev --setro %N\"\r\n<\/pre>\n<p>Then, apply the rule with the below command:<\/p>\n<pre># udevadm control -reload\r\n<\/pre>\n<h3>32. Disabling Root Access via TTY<\/h3>\n<p>To prevent the root account from performing system log-in via all console devices (tty), erase the contents of securetty file by typing the following command terminal prompt as root.<\/p>\n<pre># cp \/etc\/securetty \/etc\/securetty.bak\r\n# cat \/dev\/null &gt; \/etc\/securetty\r\n<\/pre>\n<p>Remember that this rule does not apply to SSH login sessions<br \/>\nTo prevent root login via SSH edit the file\u00a0<strong>\/etc\/ssh\/sshd_config<\/strong>\u00a0and add the below line:<\/p>\n<pre>PermitRootLogin no\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/disable-or-enable-ssh-root-login-and-limit-ssh-access-in-linux\/\" target=\"_blank\" rel=\"noopener\">Enable or Disable SSH Root Login and Limit SSH Access<\/a><br \/>\n<a href=\"https:\/\/www.tecmint.com\/5-best-practices-to-secure-and-protect-ssh-server\/\" target=\"_blank\" rel=\"noopener\">5 Best Practices to Secure and Protect SSH Server<\/a><\/p>\n<h3>33. Use POSIX ACLs to Expand System Permissions<\/h3>\n<p><a href=\"https:\/\/www.tecmint.com\/set-access-control-lists-acls-and-disk-quotas-for-users-groups\/\" target=\"_blank\" rel=\"noopener\">Access Control Lists<\/a>\u00a0can define access rights for more than just a single user or group and can specify rights for programs, processes, files, and directories. If you set ACL on a directory, its descendants will inherit the same rights automatically.<\/p>\n<p>For example,<\/p>\n<pre># setfacl -m u:user:rw file\r\n# getfacl file\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/set-access-control-lists-acls-and-disk-quotas-for-users-groups\/\" target=\"_blank\" rel=\"noopener\">Setup ACL and Disk Quotas for Users\/Groups in Linux<\/a><\/p>\n<h3>34. Setup SELinux in Enforce Mode<\/h3>\n<p>The\u00a0<strong>SELinux<\/strong>\u00a0enhancement to the Linux kernel implements the\u00a0<a href=\"https:\/\/www.tecmint.com\/selinux-essentials-and-control-filesystem-access\/\" target=\"_blank\" rel=\"noopener\">Mandatory Access Control (MAC) policy<\/a>, allowing users to define a security policy that provides granular permissions for all users, programs, processes, files, and devices.<\/p>\n<p>The kernel\u2019s access control decisions are based on all the security relevant context and not on the authenticated user identity.<\/p>\n<p>To get\u00a0<strong>Selinux<\/strong>\u00a0status and enforce policy run the below commands:<\/p>\n<pre># getenforce\r\n# setenforce 1\r\n# sestatus\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/selinux-essentials-and-control-filesystem-access\/\" target=\"_blank\" rel=\"noopener\">Setup Mandatory Access Control Policy with SELinux<\/a><\/p>\n<h3>35. Install SELinux Additional Utilities<\/h3>\n<p>Install\u00a0<strong>policycoreutils-python<\/strong>\u00a0package which provides additional Python utilities for operating\u00a0<strong>SELinux<\/strong>:\u00a0<strong>audit2allow<\/strong>,\u00a0<strong>audit2why<\/strong>,\u00a0<strong>chcat<\/strong>, and\u00a0<strong>semanage<\/strong>.<\/p>\n<p>To display all boolean values together with a short description, use the following command:<\/p>\n<pre># semanage boolean -l\r\n<\/pre>\n<p>For instance, to display and set the value of\u00a0<strong>httpd_enable_ftp_server<\/strong>, run the below command:<\/p>\n<pre># getsebool httpd_enable_ftp_server\r\n<\/pre>\n<p>To make the value of a boolean persist across reboots, specify the\u00a0<code>-P<\/code>\u00a0option to\u00a0<strong>setsebool<\/strong>, as illustrated on the following example:<\/p>\n<pre># setsebool -P httpd_enable_ftp_server on\r\n<\/pre>\n<h3>36. Use Centralized Log Server<\/h3>\n<p>Configure\u00a0<strong>rsyslog<\/strong>\u00a0daemon to send sensitive utilities log messages to a centralized log server. Also,\u00a0<a href=\"https:\/\/www.tecmint.com\/yum-package-management-cron-job-scheduling-monitoring-linux-logs\/\" target=\"_blank\" rel=\"noopener\">monitor log files with the help of logwatch utility<\/a>.<\/p>\n<p>Sending log messages to a remote server assures that once the system has been compromised, the malicious users cannot completely hide their activity, always leaving traces on remote log files.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/best-linux-log-monitoring-and-management-tools\/\" target=\"_blank\" rel=\"noopener\">4 Best Linux Log Monitoring and Management Tools<\/a><\/p>\n<h3>37. Enable Process Accounting<\/h3>\n<p>Enable process accounting by installing\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-monitor-user-activity-with-psacct-or-acct-tools\/\" target=\"_blank\" rel=\"noopener\">psacct utility<\/a>.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-monitor-user-activity-with-psacct-or-acct-tools\/\" target=\"_blank\" rel=\"noopener\">Monitor Linux User Activity with psacct or acct Tools<\/a><\/p>\n<p>Use\u00a0<strong>lastcomm<\/strong>\u00a0command to displays information about previously executed commands as recorded in the system accounting file and\u00a0<strong>sa<\/strong>\u00a0to summarize information about previously executed commands as recorded in the system accounting file.<\/p>\n<h3>38. Hardening \/etc\/sysctl.conf<\/h3>\n<p>Use the following kernel parameters rules to protect the system:<\/p>\n<h4>Disabling Source Routing<\/h4>\n<pre>net.ipv4.conf.all.accept_source_route=0\r\n<\/pre>\n<h4>Disable IPv4 forwarding<\/h4>\n<pre>ipv4.conf.all.forwarding=0\r\n<\/pre>\n<h4>Disable IPv6<\/h4>\n<pre>net.ipv6.conf.all.disable_ipv6 = 1\r\nnet.ipv6.conf.default.disable_ipv6 = 1\r\nnet.ipv6.conf.lo.disable_ipv6 = 1\r\n<\/pre>\n<p>Disable the acceptance and sending of ICMP redirected packets unless specifically required.<\/p>\n<pre>net.ipv4.conf.all.accept_redirects=0\r\nnet.ipv4.conf.all.secure_redirects=0\r\nnet.ipv4.conf.all.send_redirects=0\r\n<\/pre>\n<h4>Disable Reverse Path Forwarding<\/h4>\n<pre>net.ipv4.conf.all.rp_filter=2\r\n<\/pre>\n<p>Ignore all ICMP echo requests (set to 1 to enable)<\/p>\n<pre>net.ipv4.icmp_echo_ignore_all = 0\r\n<\/pre>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/change-modify-linux-kernel-runtime-parameters\/\" target=\"_blank\" rel=\"noopener\">Set Kernel Runtime Parameters in a Persistent and Non-Persistent Way<\/a><\/p>\n<h3>39. Use VPN Services to Access your Premises over Unprotected Public Networks<\/h3>\n<p>Always use\u00a0<strong>VPN<\/strong>\u00a0services for carriers to remotely access LAN premises over Internet. Such type of services can be configured using a free open source solution, such as\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-openvpn-server-with-linux-and-windows-clients-in-centos-rhel\/\" target=\"_blank\" rel=\"noopener\">OpenVPN<\/a>, or using a proprietary solution, such as Cisco VPN (install\u00a0<strong>vpnc<\/strong>\u00a0command-line utility provided by\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-enable-epel-repository-for-rhel-centos-6-5\/\" target=\"_blank\" rel=\"noopener\">Epel Repositories<\/a>).<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-openvpn-server-with-linux-and-windows-clients-in-centos-rhel\/\" target=\"_blank\" rel=\"noopener\">Install OpenVPN Server with Windows Clients in CentOS 7<\/a><\/p>\n<h3>40. Perform External System Scan<\/h3>\n<p>Evaluate your system security for vulnerabilities by scanning the system from remote points over your LAN using specific tools such as:<\/p>\n<ol>\n<li><strong>Nmap<\/strong>\u00a0\u2013 network scanner\u00a0<a href=\"https:\/\/www.tecmint.com\/nmap-command-examples\/\" target=\"_blank\" rel=\"noopener\">29 Examples of Nmap Command<\/a><\/li>\n<li><strong>Nessus<\/strong>\u00a0\u2013\u00a0<a href=\"https:\/\/www.tenable.com\/products\/nessus-vulnerability-scanner\" target=\"_blank\" rel=\"noopener\">security scanner<\/a><\/li>\n<li><strong>OpenVAS<\/strong>\u00a0\u2013 used to scan for vulnerabilities and for comprehensive vulnerability management.<\/li>\n<li><strong>Nikto<\/strong>\u00a0\u2013 an excellent common gateway interface (CGI) script scanner\u00a0<a href=\"https:\/\/www.tecmint.com\/nikto-a-web-application-vulnerability-and-cgi-scanner-for-web-servers\/\" target=\"_blank\" rel=\"noopener\">Scan Web Vulnerability in Linux<\/a><\/li>\n<\/ol>\n<h3>41. Protect System Internally<\/h3>\n<p>Use internal system protection against viruses, rootkits, malware and, as a good practice, install intrusion detection systems that can detect unauthorized activity (DDOS attacks, port scans), such as:<\/p>\n<ol>\n<li>AIDE \u2013 Advanced Intrusion Detection Environment \u2013\u00a0<a href=\"http:\/\/aide.sourceforge.net\/\" target=\"_blank\" rel=\"noopener\">http:\/\/aide.sourceforge.net\/<\/a><\/li>\n<li>ClamAV \u2013 Antivirus Scanner\u00a0<a href=\"https:\/\/www.clamav.net\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.clamav.net<\/a><\/li>\n<li>Rkhunter \u2013\u00a0<a href=\"https:\/\/www.tecmint.com\/install-linux-rkhunter-rootkit-hunter-in-rhel-centos-and-fedora\/\" target=\"_blank\" rel=\"noopener\">Rootkit Dcanner<\/a><\/li>\n<li><strong>Lynis<\/strong>\u00a0\u2013\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-security-auditing-and-scanning-with-lynis-tool\/\" target=\"_blank\" rel=\"noopener\">Security Auditing and Scanning Tool for Linux<\/a><\/li>\n<li><strong>Tripwire<\/strong>\u00a0\u2013 Security and Data Integrity\u00a0<a href=\"https:\/\/www.tripwire.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.tripwire.com\/<\/a><\/li>\n<li><strong>Fail2Ban<\/strong>\u00a0\u2013\u00a0<a href=\"https:\/\/www.tecmint.com\/install-fail2ban-on-rhel-centos-fedora\/\" target=\"_blank\" rel=\"noopener\">Intrusion Network Prevention<\/a><\/li>\n<li><strong>OSSEC<\/strong>\u00a0\u2013 (HIDS) Host-based Intrusion Detection System\u00a0<a href=\"https:\/\/ossec.github.io\/\" target=\"_blank\" rel=\"noopener\">http:\/\/ossec.github.io\/<\/a><\/li>\n<li><strong>Mod_Security<\/strong>\u00a0\u2013\u00a0<a href=\"https:\/\/www.tecmint.com\/protect-apache-using-mod_security-and-mod_evasive-on-rhel-centos-fedora\/\" target=\"_blank\" rel=\"noopener\">Protect Brute Force or DDoS Attacks<\/a><\/li>\n<\/ol>\n<p>Append\u00a0<strong>date<\/strong>\u00a0and\u00a0<strong>time<\/strong>\u00a0format to store commands execution by issuing the below command:<\/p>\n<pre># echo 'HISTTIMEFORMAT=\"%d\/%m\/%y  %T  \"' &gt;&gt; .bashrc'\r\n<\/pre>\n<p>Force to instantly record\u00a0<strong>HISTFILE<\/strong>\u00a0every time a command is typed (instead of logout):<\/p>\n<pre># echo \u2018PROMPT_COMMAND=\"history -a\"\u2019 &gt;&gt; .bashrc\r\n<\/pre>\n<p>Limit timeout login session. Automatically tear-down the shell when no activity is performed during idle time period. Very useful to automatically disconnect SSH sessions.<\/p>\n<pre># echo \u2018TMOUT=120\u2019 &gt;&gt; .bashrc\r\n<\/pre>\n<p>Apply all the rules by executing:<\/p>\n<pre># source .bashrc\r\n<\/pre>\n<p><strong>Read Also<\/strong>\u00a0<a href=\"https:\/\/www.tecmint.com\/set-path-variable-linux-permanently\/\" target=\"_blank\" rel=\"noopener\">Set User Environment Variables in Linux<\/a><\/p>\n<h3>43. Backup Data<\/h3>\n<p>Use backup utilities, such as\u00a0<a href=\"https:\/\/www.tecmint.com\/18-tar-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">tar<\/a>,\u00a0<a href=\"https:\/\/www.tecmint.com\/backup-or-clone-linux-partitions-using-cat-command\/\" target=\"_blank\" rel=\"noopener\">cat<\/a>,\u00a0<a href=\"https:\/\/www.tecmint.com\/rsync-local-remote-file-synchronization-commands\/\" target=\"_blank\" rel=\"noopener\">rsync<\/a>,\u00a0<a href=\"https:\/\/www.tecmint.com\/scp-commands-examples\/\" target=\"_blank\" rel=\"noopener\">scp<\/a>,\u00a0<a href=\"https:\/\/www.tecmint.com\/take-snapshot-of-logical-volume-and-restore-in-lvm\/\" target=\"_blank\" rel=\"noopener\">LVM snapshots<\/a>, etc in order to store a copy of your system, preferably offsite, in case of a system failure.<\/p>\n<p>If the system gets compromised you can perform data restore from previous backups.<\/p>\n<p>Finally, don\u2019t forget that no matter how many security measures and contra-measures you take in order to keep your system safe, you will never be 100% completely secure as long as your machine is plugged-in and powered-on.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/security-and-hardening-centos-7-guide\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial only covers general security tips for\u00a0CentOS 7\u00a0which can be used to harden the system. The checklist tips are intended to be used mostly on various types of bare-metal servers or on machines (physical or virtual) that provides network services. Security and Hardening of CentOS 7 However, some of tips can be successfully applied &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/21\/the-mega-guide-to-harden-and-secure-centos-7\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;The Mega Guide To Harden and Secure CentOS 7&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12029","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12029"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12029\/revisions"}],"predecessor-version":[{"id":12031,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12029\/revisions\/12031"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}