Skip to content

Commit

Permalink
vagrant-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaassssiiee committed Dec 12, 2024
1 parent 41e646b commit 6fa6687
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packer.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ source "hyperv-iso" "controller" {
build {
sources = ["source.azure-arm.controller", "source.hyperv-iso.controller", "source.virtualbox-iso.controller", "source.vmware-iso.controller"]

provisioner "shell" {
except = ["azure-arm.controller"]
execute_command = "bash '{{ .Path }}'"
script = "vagrant.sh"
}
provisioner "shell" {
execute_command = "echo 'vagrant' | {{ .Vars }} sudo -S -E bash '{{ .Path }}'"
scripts = ["controller.sh"]
Expand Down
17 changes: 17 additions & 0 deletions vagrant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
/usr/sbin/groupadd vagrant
/usr/sbin/useradd vagrant -g vagrant -G wheel -d /home/vagrant -c "vagrant"
echo "vagrant" | passwd --stdin vagrant
echo "installing ssh-key for vagrant"
(cd /home/vagrant && mkdir -pm 700 .ssh)

# This ssh is replaced in 'vagrant up' if the Vagrantfile has `config.ssh.insert_key = true``
cat > /home/vagrant/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
EOF
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh
restorecon -R -v /home/vagrant/.ssh
# allow vagrant user to run everything without a password
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/vagrant
chmod 0440 /etc/sudoers.d/vagrant

0 comments on commit 6fa6687

Please sign in to comment.