Cyber Security

10 Essential Linux Server Security Practices Every Sysadmin Should Know

Share on Social Media

In today’s digital landscape, ensuring your Linux Server Security is paramount. Sysadmins play a critical role in safeguarding valuable data and preventing unauthorized access. Here are ten fundamental security practices every sysadmin should implement to protect their Linux servers.

1. Keep Software Updated

Regularly update all software packages, including the Linux operating system and installed applications, to patch security vulnerabilities and bugs.

Keeping software updated in Linux is crucial for maintaining Linux server security, stability, and performance. Regularly updating software ensures that known vulnerabilities are patched, reducing the risk of exploitation by malicious actors. Linux distributions provide package management tools such as apt, yum, or pacman to easily install updates for system packages and applications.

Additionally, administrators can configure automated update mechanisms to streamline the process and ensure that critical updates are applied promptly. By staying current with software updates, Linux systems benefit from new features, bug fixes, and performance improvements, enhancing the overall reliability and efficiency of the system.

Furthermore, keeping software updated aligns with best Linux server security practices and helps organizations comply with regulatory requirements by minimizing the exposure to security threats and maintaining a secure computing environment.

Overall, prioritizing software updates is essential for protecting Linux systems and mitigating the risk of security breaches and system vulnerabilities.

Here are the commands to update software packages in various Linux distributions:

Ubuntu/Debian:

   sudo apt update
   sudo apt upgrade

Fedora:

   sudo dnf check-update
   sudo dnf upgrade

CentOS/RHEL:

   sudo yum check-update
   sudo yum update

Arch Linux:

   sudo pacman -Syu

openSUSE:

   sudo zypper refresh
   sudo zypper update

These commands will update the package lists and then upgrade installed packages to their latest versions. Always ensure you have appropriate permissions (usually through sudo) to execute these commands.

Read Also: Ultimate Guide to Linux Server Error Codes

2. Use Strong Passwords – Linux Server Hardening

Enforce the use of strong, complex passwords for Linux user accounts and encourage regular password changes to mitigate the risk of unauthorized access and better Linux server hardening.

Using strong passwords is essential for maintaining the Linux server security and integrity of user accounts and sensitive data. Strong passwords typically consist of a combination of uppercase and lowercase letters, numbers, and special characters, making them resistant to brute-force attacks and password guessing.

As a practice of OS hardening in Linux, the system enforces password complexity requirements to ensure that users create strong passwords, and administrators can further enhance security by setting password expiration policies and enforcing password history rules. By using strong passwords, users can effectively protect their accounts from unauthorized access, reducing the risk of data breaches and unauthorized activities.

Additionally, implementing multi-factor authentication (MFA) further enhances Linux server security by requiring users to provide an additional authentication factor, such as a one-time password or biometric authentication, along with their password. Overall, using strong passwords is a fundamental security practice that helps mitigate the risk of security incidents and ensures the confidentiality and integrity of Linux systems and data.

# Set a strong password for a user
sudo passwd username

Make sure to follow these guidelines to create a strong password:

  • Use a combination of upper and lowercase letters.
  • Include numbers and special characters.
  • Make it at least 8 characters long.
  • Avoid using easily guessable information like common words, names, or sequential characters.

Read Also: 3 ways to Disable USB Ports in Linux

3. Enable Linux Firewall

Enable and configure a Linux firewall to control incoming and outgoing network traffic, restricting access to only necessary services and ports.

Enabling the Linux firewall is a fundamental step for Linux server hardening and protecting against unauthorized access and malicious activities. Linux provides robust firewall solutions such as iptables or firewalld that allow administrators to define and enforce rules for incoming and outgoing network traffic.

By configuring the firewall, administrators can specify which network ports and services are accessible from the internet or local network, effectively controlling the flow of traffic to and from the system. This helps to safeguard against various network-based attacks, including port scanning, denial-of-service (DoS) attacks, and unauthorized access attempts.

Additionally, enabling the firewall enables administrators to implement security policies that comply with industry standards and regulatory requirements, ensuring the integrity, confidentiality, and availability of critical systems and data. Overall, enabling the firewall is a proactive measure for OS hardening in Linux, that strengthens the defense-in-depth strategy and contributes to the overall resilience and Linux server security posture.

Ubuntu/Debian (using ufw – Uncomplicated Firewall):

# Install firewall (UFW)
sudo apt update
sudo apt install ufw

# Enable firewall (UFW)
sudo ufw enable

# Allow SSH traffic
sudo ufw allow ssh

Fedora/RHEL/CentOS (using firewalld):

# Install Linux Firewall (firewalld)
sudo dnf install firewalld       # Fedora
sudo yum install firewalld       # RHEL/CentOS

# Enable and Start Firewall
sudo systemctl enable firewalld
sudo systemctl start firewalld

# Allow a service
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

openSUSE (using firewalld):

# Install Firewall (firewalld)
sudo zypper install firewalld

# Enable Linux Firewall
sudo systemctl enable firewalld
sudo systemctl start firewalld

# Open Linux Port
sudo firewall-cmd --zone=public --add-port=5000/tcp
sudo firewall-cmd --reload

Arch Linux (using ufw or firewalld):

# Install Firewall (UFW)
sudo pacman -S ufw

# Enable Firewall
sudo ufw enable


# Allow Service Port
sudo ufw allow 9090

4. Disable Root Login – SSH Hardening

Disable direct root login via SSH to prevent attackers from gaining unrestricted access to the server. Utilize sudo privileges for administrative tasks.

Disabling root login in Linux is a fundamental SSH hardening practice that helps in mitigate the risk of unauthorized access and potential system compromises. By default, the root account has unrestricted access to the entire system, making it a prime target for attackers. Disabling direct root login forces users to authenticate as a regular user first and then switch to the root account using tools like sudo or su. This approach adheres to the principle of least privilege, limiting the scope of potential damage in case of a security breach.

Additionally, it encourages the use of individual user accounts with limited privileges, promoting accountability and traceability in system administration tasks. System administrators can enforce this policy by modifying the SSH configuration file (/etc/ssh/sshd_config) to disallow root login, thereby enhancing the overall security posture of Linux systems and reducing the likelihood of unauthorized access or malicious activities.

# Edit SSH configuration file
sudo nano /etc/ssh/sshd_config

# Set 'PermitRootLogin' to 'no'
PermitRootLogin no

# Restart SSH service
sudo systemctl restart ssh

5. Implement SSH Key Authentication

Utilize SSH key-based authentication instead of password authentication is another SSH hardening technique for enhanced Linux server security. Generate SSH keys and configure server to accept key-based authentication.

Implementing SSH key authentication in Linux enhances security by providing a more secure and convenient method for authenticating users compared to traditional password-based authentication. SSH keys are cryptographic keys that come in pairs – a public key and a private key. The public key is stored on the server, while the private key remains with the user.

To authenticate, the client uses their private key to generate a signature, which is then verified by the server using the associated public key. This eliminates the need for passwords, making it resistant to brute-force attacks and password theft. Additionally, SSH key authentication can be further secured by encrypting the private key with a passphrase, adding an extra layer of protection.

System administrators can manage user access more effectively by centrally managing and distributing SSH keys, enabling seamless and secure access to Linux servers and ensuring compliance with security policies. Overall, implementing SSH key authentication strengthens Linux server security, enhances user experience, and reduces the risk of unauthorized access to sensitive systems and data.

# Generate SSH key pair
ssh-keygen -t rsa

# Copy public key to server
ssh-copy-id username@server_ip

6. Monitor Log Files

Regularly monitor system log files for suspicious activities, including failed login attempts, unauthorized access, and unusual network traffic.

Monitoring log files in Linux is a vital aspect of system administration and security management. Log files contain valuable information about system events, user activities, application errors, and security incidents. By regularly monitoring log files, administrators can gain insights into system performance, identify potential issues or anomalies, and detect security breaches in a timely manner. Tools like tail, grep, and awk provide powerful command-line utilities for viewing and analyzing log files in real-time, allowing administrators to track specific events or patterns of interest.

Additionally, specialized log management solutions such as Logwatch, Logrotate, and ELK Stack (Elasticsearch, Logstash, and Kibana) offer centralized log aggregation, analysis, and visualization capabilities, enabling efficient log monitoring across distributed systems. Effective log file monitoring enhances system reliability, facilitates troubleshooting, and strengthens Linux server security posture by enabling proactive detection and response to critical events.

# View authentication logs
sudo tail -f /var/log/auth.log

7. Install Security Updates Automatically

Automate the installation of security updates to ensure timely patching of vulnerabilities and minimize the risk of exploitation.

Installing security updates automatically on Linux systems is a fundamental practice in maintaining robust cybersecurity. Automating this process ensures that critical patches are applied promptly, mitigating the risk of exploitation from known vulnerabilities. Most Linux distributions offer utilities or services to facilitate automatic updates, such as unattended-upgrades on Debian-based systems and yum-cron on CentOS/RHEL systems.

These tools can be configured to download and install security updates automatically, typically during non-business hours to minimize disruption. By deploying automatic security updates, system administrators can significantly reduce the window of exposure to potential threats, enhancing the overall resilience and security posture of the Linux infrastructure.

However, it’s essential to configure these tools carefully to ensure compatibility and avoid unintended consequences, such as conflicts with custom configurations or applications. Regular monitoring and testing of automated update processes are also crucial to confirm that updates are applied successfully and do not introduce unexpected issues.

# Install unattended-upgrades package
sudo apt install unattended-upgrades

# Enable automatic updates
sudo dpkg-reconfigure unattended-upgrades

Read Also: How to install OpenVAS on Rocky Linux 9

8. Use SSL/TLS Encryption

Secure network communications by implementing SSL/TLS encryption for services such as web servers, email servers, and FTP servers.

Using SSL/TLS encryption is essential for secure communications over networks and ensuring the confidentiality, integrity, and authenticity of data transmitted between systems. SSL/TLS protocols establish encrypted connections between clients and servers, preventing eavesdropping, tampering, and unauthorized access to sensitive information. In Linux, administrators can implement SSL/TLS encryption across various services and applications, including web servers (such as Apache or Nginx), email servers (like Postfix or Sendmail), and database servers (such as MySQL or PostgreSQL).

This is typically accomplished by generating SSL/TLS certificates and configuring the respective services to use them. Additionally, tools like OpenSSL provide utilities for managing certificates, generating key pairs, and verifying cryptographic operations. By leveraging SSL/TLS encryption, Linux system administrators can safeguard data transmission and protect against security threats, thereby enhancing the overall security posture of their systems and networks.

# Install Let's Encrypt Certbot
sudo apt install certbot python3-certbot-nginx

# Obtain SSL certificate
sudo certbot --nginx

9. Limit User Access – OS Hardening in Linux

Restrict user access to only necessary commands and directories using permissions, groups, and access control lists (ACLs).

Limiting user access in a Linux operating system is a critical aspect of ensuring Linux server security and protecting sensitive data from unauthorized access or malicious activities. By implementing access controls, system administrators can enforce restrictions on users’ abilities to perform certain actions or access specific resources within the system. This can be achieved through various means, such as user permissions, file system permissions, and access control lists (ACLs).

Through user permissions, administrators can define which users have the authority to execute certain commands or access particular files and directories. File system permissions, including read, write, and execute permissions for owner, group, and other users, allow fine-grained control over who can manipulate or view files.

Additionally, ACLs offer more granular control by enabling administrators to define custom access rules for individual users or groups. By limiting user access effectively, Linux system administrators can minimize the risk of unauthorized activities and bolster the overall Linux server security.

# Set file permissions
chmod 700 /path/to/directory

# Set user group ownership
chown -R username:groupname /path/to/directory

Read Also: Install OpenSCAP Tool on Rocky Linux 9

10. Regularly Back Up Data

Implement regular data backups to safeguard against data loss due to security breaches, hardware failures, or other unforeseen circumstances.

Regularly backing up data on a Linux server is a crucial aspect of maintaining system reliability and ensuring data integrity. By implementing a consistent backup strategy, administrators can safeguard against data loss due to hardware failures, software issues, accidental deletions, or security breaches. Using tools like rsync, tar, or even dedicated backup solutions, system administrators can automate the process of creating backups of critical files, directories, databases, and configurations.

These backups should be stored securely on separate storage devices or remote servers to mitigate risks associated with local failures or disasters. Regularly scheduled backups, combined with periodic testing of restoration procedures, form the backbone of a robust data protection strategy, providing peace of mind and minimizing downtime in the event of unforeseen circumstances.

tar -czvf backup.tar.gz /path/to/directory

Explanation of the command:

  • tar: The command-line utility used for archiving files and directories.
  • -czvf: Options used to specify the operation:
    • c: Create a new archive.
    • z: Compress the archive using gzip.
    • v: Verbose mode, showing the progress of the operation.
    • f: Allows specifying the filename of the archive.
  • backup.tar.gz: The name of the compressed backup file to be created.
  • /path/to/directory: The path to the directory you want to back up.

After executing this command, a compressed backup file named backup.tar.gz will be created in the current working directory, containing all files and directories within the specified directory.

Now, use rsync or scp commands to transfer your backup files to an alternate or remote location.

# Use rsync command for data backup
sudo rsync -av --delete /path/to/source /path/to/backup

# Use scp command for backup to remote server
sudo scp username@remote_host:/path/to/remote/file /path/to/local/location

By implementing these essential Linux server security practices, sysadmins can significantly enhance the security posture of their systems, safeguarding sensitive data and protecting against potential threats.

Recommended Linux Training: Linux Command Line

Conclusion – Linux Server Security Practices:

By adopting these 10 essential Linux server security practices, sysadmins can enhance the resilience of their systems against cyber threats and better protect sensitive data and critical infrastructure. Remember, maintaining robust security requires ongoing diligence and adaptation to evolving threats, so stay informed and proactive in safeguarding your Linux servers.

Alaric Bird

Alaric Bird is a seasoned Linux System Administrator with over a decade of experience in managing and optimizing Linux-based servers and infrastructure. Known for his expertise in server deployment, security hardening, and performance tuning, Alaric has a deep understanding of various Linux distributions, including Ubuntu, CentOS, and Red Hat Enterprise Linux. His skills extend to cloud platforms like AWS, where he effectively manages virtual private servers and services. Alaric is also proficient in scripting languages such as Bash and Python, which he uses to automate routine tasks, enhancing efficiency and reliability. With a strong commitment to continuous learning, he stays updated with the latest developments in open-source technologies and best practices. His problem-solving abilities, combined with excellent communication skills, make him a valuable asset to any IT team. In addition to his technical expertise, Alaric is passionate about mentoring junior administrators and fostering a collaborative environment.

View Comments

  • Simply wish to say your article is as amazing The clearness in your post is just nice and i could assume youre an expert on this subject Well with your permission let me to grab your feed to keep updated with forthcoming post Thanks a million and please carry on the gratifying work.

Recent Posts

Puppy Linux: Fast and Simple OS

Puppy Linux is a fast, lightweight OS designed for speed and simplicity, perfect for old…

1 day ago

Change Apache Document Root in Linux

Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…

2 weeks ago

How to Change Apache Port in Linux

Discover how to change Apache port in Linux easily. Follow our simple guide to modify…

2 weeks ago

How to Create Virtual Host in Apache Server

Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…

3 weeks ago

10 Practical Tasks for RHCSA Exam with Solutions

Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…

3 weeks ago

Ultimate Fail2ban Configuration Guide

Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…

4 weeks ago

This website uses cookies.