https://github.com/iambotcoder/vagrant-remote-vm-automation
provisioning and remote command execution using Vagrant and SSH.
https://github.com/iambotcoder/vagrant-remote-vm-automation
automation devops linux remote-access ssh vagrant virtualbox
Last synced: 8 months ago
JSON representation
provisioning and remote command execution using Vagrant and SSH.
- Host: GitHub
- URL: https://github.com/iambotcoder/vagrant-remote-vm-automation
- Owner: iambotcoder
- Created: 2025-02-23T10:25:37.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-23T10:33:42.000Z (about 1 year ago)
- Last Synced: 2025-06-03T15:38:09.646Z (10 months ago)
- Topics: automation, devops, linux, remote-access, ssh, vagrant, virtualbox
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π Vagrant Virtual Machine Automation - Multi-VM Setup
---
## π Overview
This project automates the setup of multiple virtual machines using Vagrant and VirtualBox. The setup includes a **scriptbox** VM and three web servers (**web01, web02, web03**) with SSH-based authentication and remote access configurations.
---
## π Table of Contents
- [Prerequisites](#-prerequisites) π
- [Architecture](#-architecture) πΊοΈ
- [Setup & Installation](#-setup-and-installation) π οΈ
- [Vagrant Setup](#-vagrant-setup) π³
- [Key-Based Authentication](#-key-based-authentication) π
- [Cleaning Up Resources](#-cleaning-up-resources) π§Ή
- [Conclusion](#-conclusion) β
---
## π Prerequisites
Before starting, ensure you have the following installed:
- [Vagrant](https://www.vagrantup.com/downloads)
- [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
- A terminal or command prompt with administrative privileges
---
## πΊοΈ Architecture
This project sets up four virtual machines with the following specifications:
- **scriptbox (192.168.10.12)** - Controls remote access to web servers.
- **web01 (192.168.10.13)** - Web server 1 (CentOS Stream 9)
- **web02 (192.168.10.14)** - Web server 2 (CentOS Stream 9)
- **web03 (192.168.10.15)** - Web server 3 (Ubuntu Jammy 64-bit)
### Workflow:
1. **Initialize Vagrant** β Start the VMs.
2. **Modify /etc/hosts** β Map hostnames to IPs.
3. **Create Users & Grant Sudo Access** β Add `devops` user with password-less sudo.
4. **Setup SSH Key Authentication** β Enable key-based access for `devops` user.
5. **Verify Remote Access** β SSH into the web servers from `scriptbox`.
---
## π οΈ Setup & Installation
### 1β£ Initialize Vagrant:
```bash
vagrant up
```
### 2β£ Modify `/etc/hosts` on scriptbox:
```bash
sudo vim /etc/hosts
```
Add the following lines:
```plaintext
192.168.10.13 web01
192.168.10.14 web02
192.168.10.15 web03
```
### 3β£ Create `devops` User & Grant Sudo Access
For each web server, execute:
```bash
ssh vagrant@web01
sudo useradd devops
sudo passwd devops
sudo visudo
- devops ALL=(ALL) NOPASSWD: ALL (add the line in configuration file.)
```
Repeat for `web02` and `web03`.
### 4β£ Resolve SSH Issues for `web03`
Edit `/etc/ssh/sshd_config` on `web03`:
```bash
sudo vim /etc/ssh/sshd_config
```
Modify this line:
```plaintext
PasswordAuthentication yes
```
Restart SSH service:
```bash
sudo systemctl restart sshd
```
Alternatively, modify the `Vagrantfile`:
```ruby
web03.ssh.insert_key = false
```
---
## π³ Vagrant Setup
Below is the `Vagrantfile` used for this project:
```ruby
Vagrant.configure("2") do |config|
config.vm.define "scriptbox" do |scriptbox|
scriptbox.vm.box = "eurolinux-vagrant/centos-stream-9"
scriptbox.vm.network "private_network", ip: "192.168.10.12"
scriptbox.vm.hostname = "scriptbox"
scriptbox.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
end
config.vm.define "web01" do |web01|
web01.vm.box = "eurolinux-vagrant/centos-stream-9"
web01.vm.network "private_network", ip: "192.168.10.13"
web01.vm.hostname = "web01"
end
config.vm.define "web02" do |web02|
web02.vm.box = "eurolinux-vagrant/centos-stream-9"
web02.vm.network "private_network", ip: "192.168.10.14"
web02.vm.hostname = "web02"
end
config.vm.define "web03" do |web03|
web03.vm.box = "ubuntu/jammy64"
web03.vm.network "private_network", ip: "192.168.10.15"
web03.vm.hostname = "web03"
web03.ssh.insert_key = false
end
end
```
---
## π Key-Based Authentication
### 1β£ Generate SSH Key:
```bash
ssh-keygen
```
### 2β£ Copy Public Key to Web Servers:
```bash
ssh-copy-id devops@web01
ssh-copy-id devops@web02
ssh-copy-id devops@web03
```
### 3β£ Test SSH Access Without Password:
```bash
ssh devops@web01 uptime
ssh devops@web02 uptime
ssh devops@web03 uptime
```
---
## π§Ή Cleaning Up Resources
To remove the VMs and free up system resources:
### 1β£ Destroy the Virtual Machines:
```bash
vagrant destroy -f
```
### 2β£ Remove Unused Vagrant Instances:
```bash
vagrant global-status --prune
```
---
## β
Conclusion
This project automates the setup of multiple VMs using Vagrant and VirtualBox, configuring remote SSH access and key-based authentication for easy management.
---
## π¨βπ« Instructor
This project was guided by **Imran Teli**, who provided valuable mentorship throughout the process.