DEV Community

Arthur
Arthur

Posted on

7 Practical Ways to Secure a Linux Server

Hello, I'm Arthur.
Running a Linux server is not just about keeping applications online. It is also about protecting your system from unauthorized access, preventing data loss, and making sure your services remain reliable.

Whether you manage a personal project, a production website, or a development environment, basic server security should always be a priority.

In this guide, we'll explore seven practical ways to improve Linux server security, including SSH configuration, firewall rules, software updates, and monitoring.

1. Keep Your Linux System Updated

Outdated software can contain security vulnerabilities that attackers may exploit. Regular updates help protect your server and improve system stability.

On Ubuntu or Debian, run:

sudo apt update
sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

On Rocky Linux, AlmaLinux, or other RHEL-based systems, use:

sudo dnf update
Enter fullscreen mode Exit fullscreen mode

Check for updates regularly, especially on servers exposed to the internet.

For production environments, test important updates before applying them to critical services. This helps reduce the risk of unexpected downtime.

2. Secure SSH Access

SSH is commonly used to manage Linux servers remotely. However, weak passwords and unrestricted access can make it a target for attackers.

One effective improvement is to use SSH key-based authentication instead of password-based login.

Generate an SSH key on your local computer:

ssh-keygen -t ed25519
Enter fullscreen mode Exit fullscreen mode

Copy the public key to your server:

ssh-copy-id username@server_ip
Enter fullscreen mode Exit fullscreen mode

After confirming that key-based login works, you can disable password authentication.

Edit the SSH configuration file:

sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

Set the following options:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Enter fullscreen mode Exit fullscreen mode

Before restarting SSH, make sure you have tested your key-based connection in another terminal. Otherwise, you could lock yourself out.

Apply the configuration using:

sudo systemctl reload ssh
Enter fullscreen mode Exit fullscreen mode

The service name may be sshd on some distributions.

For developers who need remote access, a properly configured VPS hosting environment can provide a practical place to run applications while maintaining control over SSH settings and server access.

3. Configure a Firewall

A firewall helps control which network connections can reach your server.

Only allow the ports required by your applications.

For example, Ubuntu users can configure UFW:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Enter fullscreen mode Exit fullscreen mode

These rules allow SSH, HTTP, and HTTPS traffic while blocking other incoming connections by default.

If your SSH service uses a custom port, allow that port before enabling the firewall.

You can check the current firewall rules with:

sudo ufw status verbose
Enter fullscreen mode Exit fullscreen mode

Avoid opening unnecessary ports. Every exposed service creates another potential entry point into your system.

4. Use Separate User Accounts

Running every application and administrative task as root increases the impact of mistakes and security incidents.

Instead, create a separate account for routine administration:

sudo adduser adminuser
sudo usermod -aG sudo adminuser
Enter fullscreen mode Exit fullscreen mode

Use this account for normal administrative tasks and reserve root privileges for situations that require them.

For applications, create dedicated service accounts where appropriate.

This approach follows the principle of least privilege: each user or service should have only the permissions it needs.

5. Monitor Server Activity

Security is not only about preventing attacks. It also involves recognizing unusual activity before it becomes a serious problem.

Linux provides several useful commands for monitoring system behavior.

Check active processes:

top
Enter fullscreen mode Exit fullscreen mode

Review memory usage:

free -h
Enter fullscreen mode Exit fullscreen mode

Check disk space:

df -h
Enter fullscreen mode Exit fullscreen mode

Review recent login activity:

last
Enter fullscreen mode Exit fullscreen mode

You can also inspect authentication logs for failed login attempts.

On Ubuntu and Debian:

sudo grep "Failed password" /var/log/auth.log
Enter fullscreen mode Exit fullscreen mode

On systems that use systemd, you can inspect SSH-related events with:

sudo journalctl -u ssh --since "24 hours ago"
Enter fullscreen mode Exit fullscreen mode

Use the appropriate service name for your distribution.

If you notice repeated login failures, unexpected processes, or unfamiliar user accounts, investigate before making changes.

6. Protect Your Data with Backups

Even a well-secured server can experience hardware failures, accidental deletions, or application problems.

Regular backups help you recover when something goes wrong.

A simple backup of an application directory might look like this:

sudo tar -czf /backup/app-backup.tar.gz /var/www/html
Enter fullscreen mode Exit fullscreen mode

For production systems, consider a more complete backup strategy that includes:

  • Application files and configuration
  • Databases and user data
  • Important system settings
  • Backup retention and recovery procedures

Store backups separately from the original server whenever possible.

Most importantly, test your backups. A backup that cannot be restored is not a reliable recovery plan.

7. Choose Infrastructure That Matches Your Workload

Security also depends on the infrastructure supporting your application.

A small development project may work well on a VPS, while applications requiring dedicated hardware, greater resource isolation, or consistent performance may benefit from a dedicated server.

For example, HelloServer's dedicated server solutions provide another infrastructure option for workloads that need dedicated physical resources.

Regardless of the hosting environment, administrators should still configure access controls, apply security updates, maintain backups, and monitor their systems.

A reliable hosting environment does not replace good security practices. It supports them.

Final Thoughts

Linux server security does not require complicated tools or expensive software to get started.

Simple practices such as keeping software updated, securing SSH, configuring a firewall, limiting user permissions, and maintaining backups can significantly improve your server's security.

The key is consistency.

Review your server configuration regularly, monitor unusual activity, and test your recovery procedures before an emergency happens.

A secure server is not a one-time achievement. It is the result of ongoing maintenance, careful configuration, and a clear understanding of the systems you manage.

Top comments (0)