6 export VAGRANT_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
8 info "Preparing vagrant user..."
11 if $(grep -q 'vagrant' ${ROOTFS}/etc/shadow); then
12 log 'Skipping vagrant user creation'
13 elif $(grep -q 'ubuntu' ${ROOTFS}/etc/shadow); then
14 debug 'vagrant user does not exist, renaming ubuntu user...'
15 mv ${ROOTFS}/home/{ubuntu,vagrant}
16 chroot ${ROOTFS} usermod -l vagrant -d /home/vagrant ubuntu &>> ${LOG}
17 chroot ${ROOTFS} groupmod -n vagrant ubuntu &>> ${LOG}
18 echo -n 'vagrant:vagrant' | chroot ${ROOTFS} chpasswd
19 log 'Renamed ubuntu user to vagrant and changed password.'
20 elif [ ${DISTRIBUTION} = 'centos' -o ${DISTRIBUTION} = 'fedora' ]; then
21 debug 'Creating vagrant user...'
22 chroot ${ROOTFS} useradd --create-home -s /bin/bash -u 1000 vagrant &>> ${LOG}
23 echo -n 'vagrant:vagrant' | chroot ${ROOTFS} chpasswd
24 sed -i 's/^Defaults\s\+requiretty/# Defaults requiretty/' $ROOTFS/etc/sudoers
26 debug 'Creating vagrant user...'
27 chroot ${ROOTFS} useradd --create-home -s /bin/bash vagrant &>> ${LOG}
28 chroot ${ROOTFS} adduser vagrant sudo &>> ${LOG}
29 echo -n 'vagrant:vagrant' | chroot ${ROOTFS} chpasswd
32 # Configure SSH access
33 if [ -d ${ROOTFS}/home/vagrant/.ssh ]; then
34 log 'Skipping vagrant SSH credentials configuration'
36 debug 'SSH key has not been set'
37 mkdir -p ${ROOTFS}/home/vagrant/.ssh
38 echo $VAGRANT_KEY > ${ROOTFS}/home/vagrant/.ssh/authorized_keys
39 chroot ${ROOTFS} chown -R vagrant: /home/vagrant/.ssh
40 log 'SSH credentials configured for the vagrant user.'
43 # Enable passwordless sudo for the vagrant user
44 if [ -f ${ROOTFS}/etc/sudoers.d/vagrant ]; then
45 log 'Skipping sudoers file creation.'
47 debug 'Sudoers file was not found'
48 echo "vagrant ALL=(ALL) NOPASSWD:ALL" > ${ROOTFS}/etc/sudoers.d/vagrant
49 chmod 0440 ${ROOTFS}/etc/sudoers.d/vagrant
50 log 'Sudoers file created.'