Overview
This guide walks you through deploying a production-ready Ubuntu Linux server from scratch. You'll learn server initialization, security hardening, networking configuration, package management, systemd service setup, backup strategies, and monitoring — everything needed to run reliable production infrastructure.
Prerequisites
- A Linux server instance (VPS or dedicated): Ubuntu 24.04 LTS or 26.04 LTS recommended
- SSH client on your local machine
- A domain name (optional but recommended)
- Basic Linux command-line familiarity
Step 1: Initial Server Setup & SSH Access
1.1 Get Root Access
Upon first login, establish a secure connection:
ssh root@your_server_ip
Update your system packages immediately:
apt update && apt upgrade -y
1.2 Create a Non-Root User
Never run production services as root. Create a dedicated user:
useradd -m -s /bin/bash admin
usermod -aG sudo admin
1.3 Configure SSH Key-Based Authentication
On your local machine, generate an SSH key if you don't have one:
ssh-keygen -t ed25519 -C "admin@yourserver"
Copy the public key to your server:
ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@your_server_ip
1.4 Disable Password Authentication
Edit SSH configuration to use only keys:
sudo nano /etc/ssh/sshd_config
Set these options:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Restart SSH:
sudo systemctl restart ssh
Step 2: Security Hardening
2.1 Configure UFW Firewall
Enable the firewall and allow only necessary ports:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
2.2 Fail2Ban for Brute-Force Protection
Protect against repeated login attempts:
sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
2.3 Automatic Security Updates
sudo apt install unattended-upgrades -y
sudo systemctl enable unattended-upgrades
Step 3: Networking & Domain Configuration
3.1 Set Hostname
sudo hostnamectl set-hostname myserver.com
sudo nano /etc/hosts
Add your hostname to the hosts file.
3.2 Point Domain to Server
In your domain registrar's DNS settings, create an A record pointing your domain to your server's IP address. Allow 15-30 minutes for DNS propagation.
Step 4: Web Server & SSL Configuration
4.1 Install Nginx
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
4.2 Obtain SSL Certificate with Certbot
sudo apt install certbot python3-certbot-nginx -y
sudo certbot certonly --nginx -d yourdomain.com
Certbot automatically configures Nginx for HTTPS. Verify at https://yourdomain.com
Step 5: Package Management & Services
5.1 Install Essential Tools
sudo apt install curl wget git htop net-tools apt-transport-https -y
5.2 Create a Systemd Service (Example)
For custom applications, create a systemd service file:
sudo nano /etc/systemd/system/myapp.service
Add:
[Unit]
Description=My Application
After=network.target
[Service]
Type=simple
User=admin
WorkingDirectory=/home/admin/myapp
ExecStart=/usr/bin/python3 /home/admin/myapp/main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable myapp
sudo systemctl start myapp
Step 6: Backup & Disaster Recovery
6.1 Create a Backup Script
sudo nano /home/admin/backup.sh
Add:
#!/bin/bash
tar -czf /backups/server_backup_$(date +%Y%m%d).tar.gz /home /etc /var/www
find /backups -name "server_backup_*.tar.gz" -mtime +30 -delete
Make it executable:
chmod +x /home/admin/backup.sh
6.2 Schedule Automated Backups
sudo crontab -e
Add a daily backup at 2 AM:
0 2 * * * /home/admin/backup.sh
Step 7: Monitoring & Logging
7.1 Monitor System Resources
top # Real-time resource usage
df -h # Disk space
free -h # Memory usage
7.2 Check System Logs
sudo journalctl -xe # System logs
sudo tail -f /var/log/syslog # System messages
Common Troubleshooting
SSH Connection Refused
Verify SSH is running and port 22 is open in your firewall. Check with: sudo ufw status
Certificate Errors
Verify DNS is pointing to your server: nslookup yourdomain.com. Test with: sudo certbot renew --dry-run
Out of Disk Space
Check disk usage: df -h. Delete old logs or backups as needed.
Next Steps
You now have a production-ready Linux server. Next, you can:
- Deploy applications (Docker, Node.js, Python, etc.)
- Set up a database (PostgreSQL, MySQL)
- Configure a reverse proxy for multiple sites
- Implement load balancing for high-traffic applications
- Set up monitoring and alerting for production uptime
Learn More
For hands-on training and expert guidance, check out our Linux Freelancing Training program that covers everything from server setup through production operations.