Configuring a Linux Virtual Machine - Step-by-Step Guide
Introduction:
This guide walks you through configuring a virtual machine (VM) running a Linux distribution.
Whether on-premises with KVM, VirtualBox, or in the cloud (e.g., Azure, AWS), these steps
ensure a secure, performant, and maintainable Linux VM setup.
Prerequisites:
- Host with virtualization support (VT-x/AMD-V) enabled in BIOS
- Hypervisor installed (KVM, VirtualBox, VMware)
- ISO image of the chosen Linux distro (e.g., Ubuntu Server, CentOS)
- Sufficient RAM (>=2 GB), Storage (>=20 GB), and CPU cores.
Installation & Initial Configuration
1. Create VM:
- KVM: virt-install --name linux-vm --ram 2048 --vcpus 2 \
--disk path=/var/lib/libvirt/images/linux-vm.img,size=20 \
--os-variant ubuntu20.04 --cdrom /path/to/ubuntu.iso
2. Boot and Install OS:
- Follow installer prompts: language, keyboard, timezone.
- Partition disk: use LVM or standard partitions (/boot, swap, /).
3. Configure Networking:
- Cloud VM: installer auto-configures.
- On-prem KVM: edit /etc/netplan/*.yaml or /etc/network/interfaces, then apply:
sudo netplan apply
4. Setup SSH Access:
- Enable SSH: sudo systemctl enable --now ssh
- Secure SSH:
* Change default port in /etc/ssh/sshd_config
* Disable root login: PermitRootLogin no
* Restrict users: AllowUsers your_user
5. Create User and Set Permissions:
- sudo adduser your_user
- sudo usermod -aG sudo your_user
System Hardening & Validation
6. Firewall Configuration:
- Install UFW: sudo apt-get install ufw
- Allow SSH: sudo ufw allow ssh
- Enable UFW: sudo ufw enable
7. Regular Updates:
- Automate:
echo "0 3 * * * root apt-get update && apt-get -y upgrade" | sudo tee /etc/cron.d/auto-update
8. Monitoring and Logs:
- Install monitoring agent (e.g., Nagios NRPE, Zabbix Agent)
- Configure log rotation: edit /etc/logrotate.d/
9. Validation:
- Check services: systemctl status ssh ufw
- Verify network: ping google.com
- Disk usage: df -h
- Memory: free -m
10. Backup Strategy:
- Schedule snapshots or use rsync to backup critical data to remote storage.