Prevent running 'vagrant ssh' as root

Resolve possible issues with 'vagrant ssh' when executed as root
This commit is contained in:
Kris Lamoureux 2024-03-04 23:42:40 -05:00
parent a31bf233dc
commit 01e8e22c01
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925

View File

@ -78,7 +78,7 @@ else
fi fi
# Grab first IP or use whatever HOST_IP_FIELD is set to and check that the guest is up # Grab first IP or use whatever HOST_IP_FIELD is set to and check that the guest is up
HOST_IP="$(vagrant ssh -c "hostname -I | cut -d' ' -f${HOST_IP_FIELD:-1}" "${1:-default}" 2>/dev/null)" HOST_IP="$(sudo -u "$SUDO_USER" vagrant ssh -c "hostname -I | cut -d' ' -f${HOST_IP_FIELD:-1}" "${1:-default}" 2>/dev/null)"
if [ -z "$HOST_IP" ]; then if [ -z "$HOST_IP" ]; then
echo "[ERROR]: Failed to find ${1:-default}'s IP" echo "[ERROR]: Failed to find ${1:-default}'s IP"
exit 1 exit 1