Linux DevOps Server Setup Documentation
1. Provision a VM
Provision a virtual machine on AWS, Azure, GCP, or locally using VirtualBox.
Access the VM via SSH:
ssh user@your_vm_ip
2. Set Hostname
Check hostname:
hostname
Set hostname:
sudo hostnamectl set-hostname projectlinux
Edit /etc/hosts to map hostname:
127.0.1.1 projectlinux
3. Set Timezone
View timezone:
timedatectl
Set timezone to Asia/Karachi:
sudo timedatectl set-timezone Asia/Karachi
4. Update System Packages
Ubuntu:
sudo apt update && sudo apt upgrade -y
5. User Management
Create users:
sudo adduser webadmin
sudo adduser devops
Add to sudo group:
sudo usermod -aG sudo webadmin
sudo usermod -aG sudo devops
6. Configure Password-less Sudo
Edit sudoers:
sudo visudo
Add:
webadmin ALL=(ALL) NOPASSWD:ALL
7. Secure SSH Access
Edit SSH config:
sudo nano /etc/ssh/sshd_config
Set:
Port 2222
PermitRootLogin no
Key-based login:
ssh-keygen
ssh-copy-id -p 2222 [email protected]
8. Install Nginx
Install:
sudo apt install nginx -y
Default page:
echo 'Hello' | sudo tee /var/www/html/index.html
Start:
sudo systemctl start nginx
9. Configure Custom Web Root
Create web root:
sudo mkdir -p /srv/website
Page content:
echo 'project.local' | sudo tee /srv/website/index.html
Configure Nginx virtual host and restart Nginx.
Add to /etc/hosts:
127.0.0.1 project.local
10. Set Directory Permissions
Owner:
sudo chown -R webadmin:webadmin /srv/website
Restrict others:
sudo chmod -R 700 /srv/website
ACL for devops:
sudo apt install acl
sudo setfacl -R -m u:devops:rx /srv/website
11. Configure Backups
Create backup:
tar -czvf /backup/website-backup.tar.gz /srv/website
Cron job:
crontab -e
0 2 * * * tar -czf /backup/website-$(date +\%F).tar.gz /srv/website
12. Configure UFW
Install and allow ports:
sudo apt install ufw -y
sudo ufw allow 2222/tcp
sudo ufw allow 80/tcp
Default deny:
sudo ufw default deny incoming
sudo ufw enable
13. Monitor Logs and System
Nginx logs:
less /var/log/nginx/access.log
System:
top, htop, uptime, journalctl
14. Troubleshooting
403 - check permissions
404 - missing index.html
Disk full - cleanup /var/cache
Permission denied - fix chmod/chown