• About PinoyLinux
    • PinoyLinux.org
    • Documentation
    • Support
    • Feedback
Skip to content
PinoyLinux
Menu
  • HOME
  • EBOOKS
  • TOPICS+
    • Artificial Intelligence
    • Containers
    • Desktop
    • DevOps
    • Linux Kernel
    • Mobile
    • Network Administration
    • Programing
    • Privacy and Security
    • Servers
    • Storage
    • System Adminstration
Menu
CentOS

Securing a Fresh CentOS 7 Server

Posted on February 13, 2019

Strengthening Security on CentOS 7: Building a Resilient Digital Fortress

A fresh CentOS 7 installation provides a clean slate, a canvas on which you can paint a robust fortress of security. In this guide, we delve into the crucial steps and strategies required to fortify your CentOS 7 server from potential vulnerabilities, ensuring a robust and resilient digital environment. Whether you’re a seasoned sysadmin or a newcomer to server management, this comprehensive walkthrough will empower you to establish a secure foundation that stands up to the challenges of today’s cybersecurity landscape.

Safeguarding an organization’s IT infrastructure is of paramount importance to shield critical data and information from potential threats. While there is no foolproof method to ensure absolute security, adopting rigorous security measures is imperative to minimize vulnerabilities.

In this context, the following guide outlines a series of meticulous steps aimed at enhancing the security posture of a CentOS 7 server. It’s important to acknowledge that even the most rigorously fortified systems can be susceptible to breaches if misconfigurations or errors are present. Therefore, your insights and corrections are highly valued to collectively reinforce the security fabric.

Creating Robust Passwords for CentOS 7 Security

  • Use a minimum password length of 12 to 14 characters, if permitted.
  • Include lowercase and uppercase alphabetic characters, numbers, and symbols.
  • Avoid character repetition, keyboard patterns, dictionary words, letter or number sequences, usernames, relative or pet names, romantic links etc.
  • Avoid using information that is or might become publicly associated with the user or the account.

Keep the System Updated

[root@localhost ~]# yum update -y

Creating a New User with SUDO Permissions on CentOS 7

Let’s create a new user.

[root@localhost ~]# useradd robert00421
[root@localhost ~]# passwd robert00421
Changing password for user robert00421.
New password:
Retype new password:

Give SUDO permission to the user.

[root@localhost ~]# visudo

Add the line after the line root ALL=(ALL:ALL) ALL:

robert00421 ALL=(ALL) ALL

Securing SSH

modify the configuration file.

[root@localhost ~]# vi /etc/ssh/ssh_config

Use a non-standard port.

Port 2494

Disable SSH root access.

#PermitRootLogin yes
#PasswordAuthentication no

Limit maximum authentication tries.

#LoginGraceTime 5m
#MaxAuthTries 3

Create an SSH banner.

[root@localhost ~]# vi ssh_banner

Create a banner according to your standard.

Add the following lines.

WARNING: Unauthorized access to this system is forbidden and will be
prosecuted by law. By accessing this system, you agree that your actions
may be monitored if unauthorized usage is suspected.

And change the banner path.

[root@localhost ~]# vi /etc/ssh/ssh_config

#Banner /root/ssh_banner

Modify the MOTD.

[root@localhost ~]# vi /etc/motd

Add the following lines.

WARNING: Unauthorized access to this system is forbidden and will be
prosecuted by law. By accessing this system, you agree that your actions
may be monitored if unauthorized usage is suspected.

Limit SSH users logins.

[root@localhost ~]# echo "AllowUsers admin robert00421" >> /etc/ssh/sshd_config

Allow the SSH new port to the firewall.

[root@localhost ~]# firewall-cmd --add-port 2494/tcp
success
[root@localhost ~]# firewall-cmd --add-port 2494/tcp --permanent
success

Restart SSH daemon.

[root@localhost ~]# systemctl restart sshd

Fail2ban

Install the fail2band.

[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# yum install fail2ban -y

Make a copy of the jail.conf file and save it with the name jail.local

[root@localhost ~]# cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

Create a *.local file according to your organization standard.

[root@localhost ~]# vi /etc/fail2ban/jail.d/sshd.local

Add the following lines.

[sshd]
enabled = true
port = ssh
#action = firewallcmd-ipset
logpath = %(sshd_log)s
maxretry = 5
bantime = 86400

Restart fail2ban services.

[root@localhost ~]# systemctl restart fail2ban

Check the status of fail2ban jails.

[root@localhost jail.d]# fail2ban-client status
Status
|- Number of jail: 1
`- Jail list: sshd

Networking

Turn off IPV6.

[root@localhost ~]# sysctl -w net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.all.disable_ipv6 = 1
[root@localhost ~]# sysctl -w net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6 = 1

To make settings effective.

sysctl -p

Turn off IPV6.

[root@localhost ~]# vi /etc/sysconfig/network

Add the following lines.

NETWORKING_IPV6=no
IPV6INIT=no

Ignore ICMP or broadcast request.

[root@localhost ~]# vi /etc/sysctl.conf

Add the following lines.

Ignore ICMP request:
net.ipv4.icmp_echo_ignore_all = 1

Ignore Broadcast request:
net.ipv4.icmp_echo_ignore_broadcasts = 1

Firewalling

Accept all incoming SSH.

[root@localhost ~]# iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport 2494-j ACCEPT

Drop all incoming SSH.

[root@localhost ~]# iptables -A INPUT -p tcp --dport 2494-j DROP

Save the changes.

[root@localhost ~]# iptables-save

then reboot.

[root@localhost ~]# reboot

I don’t mention all other things that need to secure, because my goal on this blog is to secure fresh install CentOS 7 server and no services running yet.

Thanks for reading, if I’m wrong please let me know by sending me an email on canarerobertjohn@gmail.com

Author Profile

Canare
Latest entries
  • CentOSPrivacy and SecurityFebruary 13, 2019Securing a Fresh CentOS 7 Server

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Breaking News

  • New 'Mirrored' Network Mode Introduced in Windows Subsystem for Linux
  • Linux Threat Report: Earth Lusca Deploys Novel SprySOCKS Backdoor in Attacks on Government Entities
  • Linux Kernel Faces Reduction in Long-Term Support Due to Maintenance Challenges
  • Linux Celebrates 32 Years with the Release of 6.6-rc2 Version
  • Introducing Bavarder: A User-Friendly Linux Desktop App for Quick ChatGPT Interaction

Site Stats

  • 0
  • 11
  • 59
  • 530
  • 22,619
©2023 PinoyLinux | All Rights Reserved
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
View preferences
{title} {title} {title}