Skip to content

Instantly share code, notes, and snippets.

@spryffee
Last active December 3, 2020 07:50
Show Gist options
  • Save spryffee/2f5d8a9a502eede1db1136482b85a8c0 to your computer and use it in GitHub Desktop.
Save spryffee/2f5d8a9a502eede1db1136482b85a8c0 to your computer and use it in GitHub Desktop.
Bootstrap VM
# -*- mode: ruby -*-
# vi: set ft=ruby :
username = "agasanov"
interface_bridged = "wlp61s0"
ssh_key = "id_ed25519.pub"
Vagrant.configure("2") do |config|
config.vm.box = "centos/8"
config.vm.box_check_update = false
config.vm.hostname = "centos8"
config.vm.network "public_network", bridge: "#{interface_bridged}"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
vb.memory = "1024"
vb.cpus = 1
end
# Provision user and ssh key
config.vm.provision "file", source: "~/.ssh/#{ssh_key}", destination: "/tmp/#{ssh_key}"
config.vm.provision "shell", inline:<<-SHELL
echo 'Provision user and ssh key'
useradd -m -s /bin/bash -U #{username} -u 660 --groups wheel
mkdir /home/#{username}/.ssh
cat /tmp/#{ssh_key} > /home/#{username}/.ssh/authorized_keys
chown -R #{username}:#{username} /home/#{username}
echo "%#{username} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/#{username}
rm -f /tmp/#{ssh_key}
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment