Tools: How to Secure an Ubuntu Linux Server for Production - 2025 Update

Tools: How to Secure an Ubuntu Linux Server for Production - 2025 Update

How to Secure an Ubuntu Linux Server for Production

1. Update Your Server Regularly

2. Create a Non-Root User

3. Disable Root SSH Login

4. Change the Default SSH Port

5. Configure UFW Firewall

6. Install Fail2Ban

7. Use SSH Key Authentication

8. Secure Docker Containers

9. Enable Automatic Security Updates

10. Monitor Logs and System Activity

11. Backup Your Server

Final Thoughts

linux #ubuntu #security #devops Securing a production Linux server is one of the most important responsibilities of a system administrator. A poorly configured server can become an easy target for brute-force attacks, malware, unauthorized access, and service disruption. In this guide, I’ll share essential steps to harden and secure an Ubuntu server for production environments. Always keep your system packages updated to patch security vulnerabilities. You should also remove unused packages: Avoid using the root user directly for daily administration tasks. Add the user to the sudo group: Root login through SSH is a major security risk. Edit the SSH configuration file: Changing the default SSH port helps reduce automated brute-force attacks. Inside the SSH config file: Remember to allow the new port in your firewall. Ubuntu comes with UFW (Uncomplicated Firewall). Allow required services: Fail2Ban blocks repeated failed login attempts automatically. Enable and start the service: SSH keys are much safer than passwords. Generate SSH keys on your local machine: Copy the public key to the server: Then disable password authentication: Restart SSH afterward. If you use Docker in production: Update Docker regularly: Install unattended upgrades: Enable automatic security updates: Regular monitoring helps detect suspicious activity early. You can also use tools like: Always maintain secure backups. Recommended practices: Server security is not a one-time setup. It’s an ongoing process that requires continuous monitoring, updates, and optimization. A properly secured Ubuntu server reduces risks, improves reliability, and helps maintain stable production environments. If you’re managing Linux servers in production, implementing these security practices is essential. Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

$ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y -weight: 600;">sudo -weight: 500;">apt autoremove -y -weight: 600;">sudo -weight: 500;">apt autoremove -y -weight: 600;">sudo -weight: 500;">apt autoremove -y -weight: 600;">sudo adduser adminuser -weight: 600;">sudo adduser adminuser -weight: 600;">sudo adduser adminuser -weight: 600;">sudo usermod -aG -weight: 600;">sudo adminuser -weight: 600;">sudo usermod -aG -weight: 600;">sudo adminuser -weight: 600;">sudo usermod -aG -weight: 600;">sudo adminuser -weight: 600;">sudo nano /etc/ssh/sshd_config -weight: 600;">sudo nano /etc/ssh/sshd_config -weight: 600;">sudo nano /etc/ssh/sshd_config PermitRootLogin yes PermitRootLogin yes PermitRootLogin yes PermitRootLogin no PermitRootLogin no PermitRootLogin no -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh -weight: 600;">sudo ufw allow 2222/tcp -weight: 600;">sudo ufw allow 80/tcp -weight: 600;">sudo ufw allow 443/tcp -weight: 600;">sudo ufw allow 2222/tcp -weight: 600;">sudo ufw allow 80/tcp -weight: 600;">sudo ufw allow 443/tcp -weight: 600;">sudo ufw allow 2222/tcp -weight: 600;">sudo ufw allow 80/tcp -weight: 600;">sudo ufw allow 443/tcp -weight: 600;">sudo ufw -weight: 500;">enable -weight: 600;">sudo ufw -weight: 500;">enable -weight: 600;">sudo ufw -weight: 500;">enable -weight: 600;">sudo ufw -weight: 500;">status -weight: 600;">sudo ufw -weight: 500;">status -weight: 600;">sudo ufw -weight: 500;">status -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban -y -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban -y -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install fail2ban -y -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable fail2ban -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start fail2ban -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable fail2ban -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start fail2ban -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable fail2ban -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start fail2ban -weight: 600;">sudo fail2ban-client -weight: 500;">status -weight: 600;">sudo fail2ban-client -weight: 500;">status -weight: 600;">sudo fail2ban-client -weight: 500;">status ssh-copy-id user@server-ip ssh-copy-id user@server-ip ssh-copy-id user@server-ip PasswordAuthentication no PasswordAuthentication no PasswordAuthentication no -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install -weight: 500;">docker-ce -weight: 500;">docker-ce-cli containerd.io -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install -weight: 500;">docker-ce -weight: 500;">docker-ce-cli containerd.io -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install -weight: 500;">docker-ce -weight: 500;">docker-ce-cli containerd.io -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install unattended-upgrades -y -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install unattended-upgrades -y -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install unattended-upgrades -y -weight: 600;">sudo dpkg-reconfigure unattended-upgrades -weight: 600;">sudo dpkg-reconfigure unattended-upgrades -weight: 600;">sudo dpkg-reconfigure unattended-upgrades -weight: 600;">sudo journalctl -xe -weight: 600;">sudo journalctl -xe -weight: 600;">sudo journalctl -xe -weight: 600;">sudo tail -f /var/log/auth.log -weight: 600;">sudo tail -f /var/log/auth.log -weight: 600;">sudo tail -f /var/log/auth.log - Avoid running containers as root - Keep images updated - Use trusted images only - Limit exposed ports - Scan images for vulnerabilities - Uptime Kuma - Daily automated backups - Offsite storage - Database dumps - Backup verification