Hardening CentOS 7 (firewalld, selinux)

  • Posted on September 10, 2014
  • storrgieAsked by storrgie

I recently launched a CentOS 7 droplet and noticed that both firewalld and selinux were disabled by default. Does anyone have a good introductory guide on hardening CentOS 7?

I’m used to setting up an Ubuntu Server install such as:

  • ssh hardening (ports, retries, key_auth. fail2ban)
  • firewall hardening (ufw)
  • application specific hardening
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

See here: RHEL7 Security Guide

And here: RHEL7 SELinux

In particular:

systemctl start firewalld
systemctl enable firewalld


vi /etc/selinux/config
set enforcing or permissive.
shutdown -r now     (or reboot)

After reboot, confirm:


And to harden ssh: First confirm you’re able to login via ssh keys. Then generate a list of all authentication methods, like this:

man sshd_config | grep 'Authentication$'


vi /etc/ssh/sshd_config

Search for all instances of “Authentication” and comment them out. Paste the afore-generated list, as follows:

PubkeyAuthentication yes
RSAAuthentication no
ChallengeResponseAuthentication no
GSSAPIAuthentication no
HostbasedAuthentication no
KerberosAuthentication no
PasswordAuthentication no
RhostsRSAAuthentication no

And restart sshd

systemctl restart sshd