DEV Community

Cover image for Implementing and Managing Security Protocols in Linux
Chielo Chiamaka
Chielo Chiamaka

Posted on

1

Implementing and Managing Security Protocols in Linux

Introduction

If you're managing a Linux system, one of the most important responsibilities you'll take on is securing your environment.

You can’t afford to leave your system open to threats, and that’s where understanding security protocols comes in.

This guide covers essential security measures every Linux system administrator should enforce to safeguard a Linux environment effectively.

Table of Contents

1. Securing SSH Access

SSH is the main entry point for remote system administration, making it a high-priority target for attackers.

Why It Matters

Hackers scan for open SSH ports constantly, looking for weak configurations to break in. If SSH security is compromised, an attacker could take full control of the system.

Best Practices

  • Disable Root Login (Prevent direct root access)

    • Edit configuration:
    sudo nano /etc/ssh/sshd_config
    
    • Change:
    PermitRootLogin no
    
    • Restart SSH:
    sudo systemctl restart sshd
    

Why? If an attacker gains access as root, they can install malware, delete files, or shut down the server. Hackers often target root because it’s a default username, making it easier for brute-force attacks.

  • Use Key-Based Authentication Instead of Passwords

    • Generate SSH keys:
    ssh-keygen
    
    • Copy the key to the remote server:
    ssh-copy-id user@server
    

Why? Keys eliminate password-based authentication, making it impossible for attackers to brute-force their way in.

  • Consider Changing the Default SSH Port

    • Modify SSH config:
    Port 2222
    

While not a replacement for strong authentication, changing the port reduces automated scans targeting default SSH ports.

2. Managing Firewalls with Firewalld

Firewalld controls network access, defining which services can communicate with the system.

Why It Matters

Without a firewall, any service running on the system is exposed to the internet including ones that shouldn’t be accessible externally. Firewalld blocks unauthorized traffic while allowing trusted services like SSH and HTTPS.

Basic Firewall Commands

  • Check Firewall Status:
  sudo firewall-cmd --state
Enter fullscreen mode Exit fullscreen mode
  • Confirms whether Firewalld is active.

    • List Allowed Services:
  sudo firewall-cmd --list-all
Enter fullscreen mode Exit fullscreen mode
  • Shows currently permitted services and firewall rules.

    • Add a Trusted Service (e.g., SSH):
  sudo firewall-cmd --permanent --add-service=ssh
  sudo firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode
  • The --permanent flag ensures rules persist after a reboot.
  • --reload applies changes immediately.

Zones in Firewalld

Zones define trust levels for network traffic:

  • Public – Least trusted (minimal access).
  • Internal – More trusted (used in private networks).
  • Trusted, External, Home, Work, Block – Various levels of restriction.

Setting the appropriate zone for each network interface ensures that services are only accessible where needed.

3. Enforcing Policies with SELinux

SELinux provides mandatory access control, preventing unauthorized programs from accessing system files—even if exploited.

Why It Matters

A compromised application could attempt to access system resources. SELinux ensures that even if an attacker gains access, they are restricted from making further changes outside predefined security rules.

Basic SELinux Commands

  • Check SELinux Status:
  getenforce
Enter fullscreen mode Exit fullscreen mode
  • Shows if SELinux is Enforcing, Permissive, or Disabled.

    • Enable Enforcing Mode Temporarily:
  sudo setenforce 1
Enter fullscreen mode Exit fullscreen mode
  • Immediately activates SELinux restrictions.

    • Make It Permanent (Survives Reboots):
  sudo nano /etc/selinux/config
Enter fullscreen mode Exit fullscreen mode
  • Change:

    SELINUX=enforcing
    
  • Save and reboot.

Troubleshooting SELinux

  • Use sealert (GUI tool for SELinux alerts)
  • Check logs for blocked actions:
  cat /var/log/audit/audit.log | grep AVC
Enter fullscreen mode Exit fullscreen mode
  • This helps diagnose issues related to SELinux restrictions.

4. Controlling Access with Users, Groups, and Permissions

Proper user management ensures files and directories are only accessible by authorized users.

Key Tools for Access Control

  • Change permissions (chmod)
  chmod 600 secret.txt
Enter fullscreen mode Exit fullscreen mode
  • Restricts access to the file’s owner.

    • Change ownership (chown)
  chown user:group file
Enter fullscreen mode Exit fullscreen mode
  • Assigns a new owner and group.

    • Grant limited admin access (sudo)
  sudo usermod -aG wheel username
Enter fullscreen mode Exit fullscreen mode
  • Adds the user to the administrator group for controlled privilege escalation.

5. Keeping the System Updated

Unpatched systems are prime targets for attackers exploiting known vulnerabilities.

Keeping Software Up to Date

  • Manually update the system:
  sudo dnf update
Enter fullscreen mode Exit fullscreen mode
  • Enable automatic updates:
  sudo dnf install dnf-automatic
  sudo systemctl enable --now dnf-automatic.timer
Enter fullscreen mode Exit fullscreen mode
  • This ensures regular background updates, reducing security risks.

6. Monitoring and Auditing Activity

Tracking who did what on the system ensures accountability and security.

Key Log Files

  • Authentication logs:
  /var/log/secure
Enter fullscreen mode Exit fullscreen mode
  • System-wide logs:
  journalctl
Enter fullscreen mode Exit fullscreen mode
  • Security audit logs:
  auditd (audit service)
Enter fullscreen mode Exit fullscreen mode

Using auditd to Monitor Activity

  1. Enable auditd:
   sudo systemctl enable --now auditd
Enter fullscreen mode Exit fullscreen mode
  1. Check audit logs for specific user actions:
   sudo ausearch -ua yourusername
Enter fullscreen mode Exit fullscreen mode
  • Helps track security-related activities.

Conclusion

Implementing these security protocols ensures a stronger, more resilient Linux system.

Stay consistent with these and regularly review your systems to maintain a strong security posture.

This knowledge will serve you well whether you’re managing a single server or a complex network.

Let’s connect on LinkedIn

(https://www.linkedin.com/in/chiamaka-chielo?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app)

As I automate my journey into RHCE and Ansible, I’d love to connect with fellow learners and professionals. Feel free to reach out and join me as I share tips, resources, and insights throughout this 30-day challenge.

cloudwhistler #30daysLinuxchallenge

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!