Skip to content

Instantly share code, notes, and snippets.

@MShekow
Last active June 15, 2022 07:20
Show Gist options
  • Save MShekow/96c14d04489d79c33416e5528de156d8 to your computer and use it in GitHub Desktop.
Save MShekow/96c14d04489d79c33416e5528de156d8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Prepares the macOS VM to be usable from Vagrant
if [[ `id -u` -ne 0 ]] ; then echo "You must run this script as root" ; exit 1 ; fi
set -e
# Enable SSH
systemsetup -setremotelogin on
# Inject Vagrant's insecure public key as accepted login method (see https://github.com/hashicorp/vagrant/blob/master/keys/vagrant.pub)
if [ ! -e /Users/vagrant/.ssh ]; then
mkdir /Users/vagrant/.ssh
chmod 0700 /Users/vagrant/.ssh
chown `stat -f %u /Users/vagrant` /Users/vagrant/.ssh
fi
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" >> /Users/vagrant/.ssh/authorized_keys
chmod 0600 /Users/vagrant/.ssh/authorized_keys
chown `stat -f %u /Users/vagrant` /Users/vagrant/.ssh/authorized_keys
# Allow passwordless sudo
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
# Delete this file again
rm "$(realpath $0)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment