Skip to content
November 6, 2026

How to Secure a Linux Server: 15 Essential Steps

Linux server hardening concept, secure terminal workstation, shielded server rack, firewall and locked SSH connection, dark navy cyan premium illustration

A new Linux installation is a starting point, not a finished security design. A production server should expose only the services it needs, use controlled administrator access, receive security updates and generate logs that someone reviews. The steps below provide a practical hardening baseline. Adapt them to the server’s role and test changes before applying them to a critical system.

Before changing anything: protect access

Confirm that you have console access through the hosting provider, hypervisor or physical management interface. Keep an existing administrative SSH session open while testing changes in a second session. Take a verified backup or snapshot appropriate to the change, and understand how to roll it back. A firewall or SSH mistake can make a remote server unreachable.

1. Use a supported operating-system release

Check the distribution and release lifecycle. Plan upgrades before standard security maintenance ends. Remove obsolete kernels and packages only through a documented process, and verify application compatibility before major upgrades.

2. Apply security updates

Review security advisories and configure a repeatable patch process. Test updates for critical applications, schedule restarts and verify services after maintenance. Record exceptions rather than allowing servers to remain unpatched indefinitely.

sudo apt update
apt list --upgradable
sudo apt upgrade

3. Create named administrator accounts

Avoid shared root access. Use individual accounts with sudo, remove stale users and review who belongs to privileged groups. Named accounts improve accountability and make access removal easier when roles change.

4. Harden SSH carefully

Use key-based authentication where appropriate, protect private keys and restrict SSH to trusted source networks or a VPN. Consider disabling direct root login and password authentication only after confirming that key access works for every required administrator. Validate the configuration before reloading the SSH service.

sudo sshd -t
sudo systemctl reload ssh

Service names can vary by distribution. Check the correct service and configuration path for the system you manage.

5. Restrict network access

List listening ports and compare them with the server’s documented role. Permit only required inbound traffic. Keep databases, control panels and management interfaces off the public internet unless there is a justified, protected access design.

sudo ss -tulpn

6. Disable unnecessary services

Review enabled services and packages. Do not disable unfamiliar services simply because their names are unclear; establish whether they are required by the operating system or application. Remove unused software through the package manager and document the reason.

7. Protect secrets and configuration

Limit access to private keys, API tokens, database passwords and application configuration files. Avoid placing secrets in shell history, public repositories or shared documents. Use a suitable secret-management process and rotate credentials if exposure is suspected.

8. Set sensible file permissions

Review ownership and permissions for web roots, application files, logs and backup directories. Services should not run with more privilege than they require. Avoid broad recursive permission changes such as making an entire application directory world-writable; they can create serious security problems.

9. Synchronise system time

Use reliable time synchronisation. Accurate timestamps help correlate authentication events, application logs and security alerts across systems. Confirm time zone and clock behaviour, especially when services run across multiple locations.

10. Monitor logs and authentication

Review authentication failures, privilege escalation, unexpected service restarts and unusual network activity. Central log collection can help preserve evidence if a host is compromised. Define which events require investigation and who is responsible for responding.

11. Protect the backup path

Back up application data and configuration, protect backup credentials separately and keep copies outside the server’s normal administrative boundary. Test restores. A backup that cannot be restored within the business’s required time is not an adequate recovery plan.

12. Review certificates and exposed applications

Track certificate expiry and confirm automatic renewal works. Keep web servers, control panels, container images and application dependencies updated. Remove test pages, sample credentials and unused virtual hosts from production.

13. Document the baseline

Record the purpose of the server, open ports, firewall policy, administrators, installed services, patch schedule, backup scope and recovery procedure. Documentation should describe the actual configuration, not an ideal design that was never deployed.

14. Test changes and recovery

Use a staging system where possible. After a security change, verify the application, monitoring, backups and remote administration. Test a recovery scenario periodically so the team knows what to do during an incident.

15. Review continuously

Hardening is not a one-time checklist. Revisit access, exposed services, patch status and logs after application changes, new integrations or staff changes. Review the baseline on a schedule and track exceptions with an owner and expiry date.

Frequently asked questions

Should every Linux server use the same firewall rules?

No. Rules should reflect the server’s role and required communication. A public web server, database server and internal monitoring node have different exposure needs.

Is changing the SSH port enough?

No. It may reduce routine scanning noise, but it does not replace authentication controls, network restrictions, patching or monitoring.

Can I apply a hardening script to every server?

Only after understanding what it changes and testing it against the workload. Scripts can break applications or lock out administrators if assumptions do not match the environment.

How SmartSite can help

SmartSite supports organisations across Ireland with Linux server administration, VPS hosting, security and connectivity, monitoring and backup planning. Explore security services or contact SmartSite for a practical review.

Do not copy hardening settings without testing

Security baselines are useful starting points, but a server’s role matters. A web server may need public HTTP and HTTPS access; a database server should normally accept connections only from approved application networks. A monitoring node may need agent traffic from managed hosts. Apply controls according to the documented role and test the application after each significant change.

Keep an exception register for settings that cannot be applied. Record the reason, risk owner, compensating control and review date. An undocumented exception can become permanent even after the original application or business need has disappeared.

What to do after a suspected compromise

Use the organisation’s incident process. Preserve relevant logs, record the time and affected systems, restrict access where safe and involve the responsible security or hosting contacts. Do not immediately wipe a host if evidence may be needed to understand the incident. Once containment and investigation are complete, rebuild from trusted sources where appropriate, rotate exposed credentials and restore only verified data. Test the recovery before returning the service to normal use.