惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
V2EX
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
The Cloudflare Blog
T
Tailwind CSS Blog
H
Help Net Security
腾讯CDC
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
C
Check Point Blog
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Secure an Ubuntu Linux Server for Production
Sovrab Roy · 2026-05-09 · via DEV Community

Sovrab Roy

How to Secure an Ubuntu Linux Server for Production

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.


1. Update Your Server Regularly

Always keep your system packages updated to patch security vulnerabilities.

sudo apt update && sudo apt upgrade -y

Enter fullscreen mode Exit fullscreen mode

You should also remove unused packages:

sudo apt autoremove -y

Enter fullscreen mode Exit fullscreen mode


2. Create a Non-Root User

Avoid using the root user directly for daily administration tasks.

Create a new user:

sudo adduser adminuser

Enter fullscreen mode Exit fullscreen mode

Add the user to the sudo group:

sudo usermod -aG sudo adminuser

Enter fullscreen mode Exit fullscreen mode


3. Disable Root SSH Login

Root login through SSH is a major security risk.

Edit the SSH configuration file:

sudo nano /etc/ssh/sshd_config

Enter fullscreen mode Exit fullscreen mode

Find:

PermitRootLogin yes

Enter fullscreen mode Exit fullscreen mode

Change it to:

PermitRootLogin no

Enter fullscreen mode Exit fullscreen mode

Restart SSH:

sudo systemctl restart ssh

Enter fullscreen mode Exit fullscreen mode


4. Change the Default SSH Port

Changing the default SSH port helps reduce automated brute-force attacks.

Inside the SSH config file:

Port 2222

Enter fullscreen mode Exit fullscreen mode

Restart SSH:

sudo systemctl restart ssh

Enter fullscreen mode Exit fullscreen mode

Remember to allow the new port in your firewall.


5. Configure UFW Firewall

Ubuntu comes with UFW (Uncomplicated Firewall).

Allow required services:

sudo ufw allow 2222/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Enter fullscreen mode Exit fullscreen mode

Enable the firewall:

sudo ufw enable

Enter fullscreen mode Exit fullscreen mode

Check status:

sudo ufw status

Enter fullscreen mode Exit fullscreen mode


6. Install Fail2Ban

Fail2Ban blocks repeated failed login attempts automatically.

Install it:

sudo apt install fail2ban -y

Enter fullscreen mode Exit fullscreen mode

Enable and start the service:

sudo systemctl enable fail2ban
sudo systemctl start fail2ban

Enter fullscreen mode Exit fullscreen mode

Check status:

sudo fail2ban-client status

Enter fullscreen mode Exit fullscreen mode


7. Use SSH Key Authentication

SSH keys are much safer than passwords.

Generate SSH keys on your local machine:

ssh-keygen

Enter fullscreen mode Exit fullscreen mode

Copy the public key to the server:

ssh-copy-id user@server-ip

Enter fullscreen mode Exit fullscreen mode

Then disable password authentication:

PasswordAuthentication no

Enter fullscreen mode Exit fullscreen mode

Restart SSH afterward.


8. Secure Docker Containers

If you use Docker in production:

  • Avoid running containers as root
  • Keep images updated
  • Use trusted images only
  • Limit exposed ports
  • Scan images for vulnerabilities

Update Docker regularly:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

Enter fullscreen mode Exit fullscreen mode


9. Enable Automatic Security Updates

Install unattended upgrades:

sudo apt install unattended-upgrades -y

Enter fullscreen mode Exit fullscreen mode

Enable automatic security updates:

sudo dpkg-reconfigure unattended-upgrades

Enter fullscreen mode Exit fullscreen mode


10. Monitor Logs and System Activity

Regular monitoring helps detect suspicious activity early.

Useful commands:

sudo journalctl -xe

Enter fullscreen mode Exit fullscreen mode

sudo tail -f /var/log/auth.log

Enter fullscreen mode Exit fullscreen mode

You can also use tools like:

  • Prometheus
  • Grafana
  • Netdata
  • Uptime Kuma

11. Backup Your Server

Always maintain secure backups.

Recommended practices:

  • Daily automated backups
  • Offsite storage
  • Database dumps
  • Backup verification

Tools:

  • rsync
  • BorgBackup
  • Restic
  • Rclone

Final Thoughts

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.


linux #ubuntu #security #devops



Enter fullscreen mode Exit fullscreen mode