sammlinux sammlinux
  • Ubuntu
    UbuntuShow More
    How To Install and Use Docker CE on Ubuntu 22.04
    26 Min Read
    How To Install and Secure phpMyAdmin on Ubuntu 22.04
    5 Min Read
    How To Secure SSH with Fail2Ban on Ubuntu 22.04
    8 Min Read
    How To Install Uptime Kuma on Ubuntu 22.04
    17 Min Read
    How To Install Ubuntu Server 22.04 LTS with Screenshots
    14 Min Read
  • Rocky Linux
    Rocky LinuxShow More
    How To Install phpMyAdmin on Rocky Linux 9
    15 Min Read
    How To Secure SSH with Fail2Ban on Rocky Linux 9
    12 Min Read
    How To Install Rocky Linux 9.2 Server with Screenshots
    12 Min Read
    How To Set Up a Firewall Using FirewallD on Rocky Linux 9
    8 Min Read
    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide
    10 Min Read
  • Debian
    DebianShow More
    How To Secure SSH with Fail2Ban on Debian 11
    8 Min Read
    How To Install Debian 11 (Bullseye) Server with Pictures
    12 Min Read
    How To Install and Setup Node.js on Debian 11
    6 Min Read
    How To Install PHP 8.2 on Debian 11
    12 Min Read
    How To Install Nginx on Debian 11: A Comprehensive Guide
    9 Min Read
  • Linux
    LinuxShow More
    Best Practices Linux Server Security for System Administrator
    8 Min Read
    A Simple Guide: How To Manage Groups on Linux
    5 Min Read
    How To Manage Log Files Using Logrotate In Linux
    7 Min Read
    The Easy Ways to Check File Size in Linux
    7 Min Read
    How To Backup Files From Remote Linux VPS Using Rsync Script
    12 Min Read
  • CentOS
    CentOSShow More
    How To Secure SSH with Fail2Ban on CentOS 7
    9 Min Read
    How To Install PHP 8.2 on CentOS 7 / RHEL 7
    18 Min Read
    How To Install Apache Web Server on CentOS 7
    11 Min Read
    How To Set Up a Firewall Using FirewallD on CentOS 7
    5 Min Read
    Initial Setup CentOS 7 Server: Secure and Efficient
    9 Min Read
  • DevOps
    DevOpsShow More
    How To Create AWS CloudFront: A Step-by-Step Guide
    10 Min Read
Reading: Initial Setup CentOS 7 Server: Secure and Efficient
Share
Font ResizerAa
Linux for BeginnersLinux for Beginners
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Search
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.

Initial Setup CentOS 7 Server: Secure and Efficient

Samuel Siahaan
By Samuel Siahaan
Last updated: September 10, 2023
SHARE

CentOS 7, a popular choice for server environments, offers robust features and stability. However, to make the most of it, you need to set it up correctly. In this guide, we’ll walk you through the initial setup of your CentOS 7 server, focusing on security and efficiency. By the end, you’ll have a server that’s not only secure but also optimized for peak performance.

Contents
Table of ContentsThe Importance of Initial Server SetupStep 1: Access Your CentOS 7 ServerStep 2: Update the System CentOS 7 ServerStep 3: Create a New UserGranting Administrative PrivilegesStep 4: Securing OpenSSH on CentOS 7 ServerStep 5: Configure the Firewall on CentOS 7 ServerStep 6: Install Fail2Ban on CentOS 7 ServerStep 7: Set Up Automatic UpdatesStep 8: Optimize Server PerformanceSwap SpaceDisable Unnecessary ServicesConclusion

Table of Contents

  • The Importance of Initial Server Setup
    • Step 1: Access Your CentOS 7 Server
    • Step 2: Update the System CentOS 7 Server
    • Step 3: Create a New User
      • Granting Administrative Privileges
    • Step 4: Securing OpenSSH on CentOS 7 Server
    • Step 5: Configure the Firewall on CentOS 7 Server
    • Step 6: Install Fail2Ban on CentOS 7 Server
    • Step 7: Set Up Automatic Updates
    • Step 8: Optimize Server Performance
      • Swap Space
      • Disable Unnecessary Services
  • Conclusion

The Importance of Initial Server Setup

Firstly performing the initial setup of your CentOS 7 server is crucial for several reasons:

  • Security: A properly configured server is less vulnerable to security threats.
  • Efficiency: An efficiently configured server maximizes resource utilization and reduces downtime.

Now, let’s dive into the step-by-step process.

Step 1: Access Your CentOS 7 Server

To begin, you need access to your CentOS 7 server either physically or via SSH (Secure Shell). If you’re connecting remotely, make sure you have your server’s IP address and credentials.

- Advertisement -

Step 2: Update the System CentOS 7 Server

Start by ensuring your server’s software is up to date. Run the following command:

Bash
[root@centos7 ~]# yum update

This command will update all installed packages to their latest versions, including security patches.

Step 3: Create a New User

Once you are logged in as root, you can create a new user account that you will use to log in from now on. It’s good practice not to use the root user for day-to-day tasks. Create a new user with sudo privileges to enhance security:

This example creates a new user called samm, but you should replace it with any username that you prefer:

Bash
[root@centos7 ~]# adduser yourusername
[root@centos7 ~]# passwd yourusername
[root@centos7 ~]# usermod -aG wheel yourusername

Replace yourusername with the desired username.

- Advertisement -

Granting Administrative Privileges

Now, you have a new user account with regular account privileges. However, you may sometimes need to perform administrative tasks.

To avoid having to log out of your regular user and log back in as the root account, you can set up what is known as “superuser” or root privileges for your regular account. This will allow your regular user to run commands with administrative privileges by putting the word sudo before each command.

To add these privileges to your new user, you need to add the new user to the wheel group. By default, on CentOS 7 server, users who belong to the wheel group are allowed to use the sudo command.

- Advertisement -

As root, run this command to add your new user to the wheel group with the following command:

Bash
[root@centos7 ~]# usermod -aG wheel yourusername

Now, when logged in as your regular user, you can type sudo before commands to perform actions with superuser privileges.

Step 4: Securing OpenSSH on CentOS 7 Server

For added security, you can do a few ways like disable root login via SSH, disable password-based authentication and use SSH keys for authentication or change the default SSH port (22). Here are some recommended configurations:

Bash
[root@centos7 ~]# nano /etc/ssh/sshd_config
  • Disable Root Login: Prevent root login directly through SSH. Create a separate user with sudo privileges for administrative tasks. Locate the line PermitRootLogin and set it to no.
  • Use SSH Key Authentication: Disable password-based authentication and use SSH keys for authentication. This is highly recommended for security. Locate the line PasswordAuthentication and set it to no.
  • Change SSH Port (Optional): You can change the default SSH port (22) to a custom port for added security. Make sure the chosen port is not used by other services. Locate the line Port and set it to 2222.

Then save the file and restart the SSH service with the following commands:

Bash
[root@centos7 ~]# systemctl restart sshd

Step 5: Configure the Firewall on CentOS 7 Server

CentOS 7 comes with a built-in firewall, firewalld. To allow essential services, use the following commands:

Bash
[root@centos7 ~]# firewall-cmd --permanent --add-service=ssh
[root@centos7 ~]# firewall-cmd --permanent --add-service=http
[root@centos7 ~]# firewall-cmd --reload

This configuration allows SSH and HTTP traffic, but you can adapt it to your specific needs.

Step 6: Install Fail2Ban on CentOS 7 Server

Fail2Ban basically is a security tool that protects your server against brute-force attacks. Install it using the following command:

Bash
[root@centos7 ~]# yum install fail2ban

After installation, start the service and enable it to start on boot with the following command:

Bash
[root@centos7 ~]# systemctl start fail2ban
[root@centos7 ~]# systemctl enable fail2ban

Step 7: Set Up Automatic Updates

To keep your server secure, configure automatic updates with the following command:

Bash
[root@centos7 ~]# yum install yum-cron
[root@centos7 ~]# systemctl start yum-cron
[root@centos7 ~]# systemctl enable yum-cron

This ensures that your system stays up to date specifically with security patches.

Step 8: Optimize Server Performance

Additionally enhance your server’s efficiency with a few optimizations:

Swap Space

Create a swap file to improve memory management with the following command:

Bash
[root@centos7 ~]# fallocate -l 1G /swapfile
[root@centos7 ~]# chmod 600 /swapfile
[root@centos7 ~]# mkswap /swapfile
[root@centos7 ~]# swapon /swapfile

Disable Unnecessary Services

Identify and disable services you don’t need with the following command:

Bash
[root@centos7 ~]# systemctl list-unit-files | grep enabled
[root@centos7 ~]# systemctl disable servicename

Replace <service-name> with the service you want to disable.

Conclusion

Lastly Congratulations! You’ve successfully completed the initial setup of your CentOS 7 server with a strong focus on security and efficiency. By following these steps, you’ve created a solid foundation for hosting websites, applications, or services.

Remember that server security is an ongoing process. Regularly monitor and update your server to stay protected against emerging threats. Additionally, fine-tune your server’s configuration to meet your specific needs.

While this guide has equipped you with the essential knowledge to set up a secure and efficient CentOS 7 server. Use it as a reference as you continue to manage and optimize your server for peak performance.

Also Read Our Other Guides :

  • Initial Setup Rocky Linux 9 Server: Secure and Efficient
  • Initial Setup Ubuntu Server 22.04: Secure and Efficient
  • Initial Setup Debian 11 Server: Secure and Efficient
  • How To Set Up a Firewall Using FirewallD on CentOS 7
  • How To Set Up a Firewall Using FirewallD on Rocky Linux 9
  • How To Install RTMP Server with Nginx on CentOS 7

Finally, now you have learned initial setup CentOS 7 Server with secure and efficient.

TAGGED:CentOSClean InstallInitial SetupSecurityServer Guide

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article How To Install Nginx on Rocky Linux 9: A Comprehensive Guide
Next Article How To Set Up a Firewall with UFW on Ubuntu 22.04
Leave a Comment

Leave a Reply Cancel reply

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

How To Install and Secure phpMyAdmin on Ubuntu 22.04
Ubuntu
Install and Configure Docker Swarm Mode on Centos 7
CentOS
How To Install and Config Thumbor on Debian 10
Debian
How To Install MariaDB 10.6 on Debian 11 Server
Debian
How To Install MongoDB 6.0 on Debian 10 & 11
Debian

You Might Also Like

Linux

Best Practices Linux Server Security for System Administrator

8 Min Read
Rocky Linux

How To Install a MinIO Object Storage Server on Rocky Linux (Part 2)

14 Min Read
CentOS

How To Install Apache Web Server on CentOS 7

11 Min Read
Rocky Linux

How To Install Rocky Linux 9.2 Server with Screenshots

12 Min Read
Rocky Linux

How To Install and Configure Ansible on Rocky Linux 9

15 Min Read
Linux

How To Configure SSH Key-based Authentication In Linux

7 Min Read
Ubuntu

How To Set Up a Firewall with UFW on Ubuntu 22.04

7 Min Read
Rocky Linux

How To Set Up a Firewall Using FirewallD on Rocky Linux 9

8 Min Read
Show More

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

sammlinux sammlinux

Providing beginner-friendly Linux tutorials and open-source guides to simplify your digital infrastructure.

www.sammlinux.com © 2026 | All Rights Reserved

Join Us!
Subscribe to our newsletter and never miss our latest news, podcasts etc.

Subscribe to our newsletter to get our newest articles instantly!

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?