From 01e8e22c01439fa71d6a79dad06c8dfbe52b6f8a Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Mon, 4 Mar 2024 23:42:40 -0500 Subject: [PATCH] Prevent running 'vagrant ssh' as root Resolve possible issues with 'vagrant ssh' when executed as root --- forward-ssh.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forward-ssh.sh b/forward-ssh.sh index 9175498..ffb28ac 100755 --- a/forward-ssh.sh +++ b/forward-ssh.sh @@ -78,7 +78,7 @@ else fi # 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 echo "[ERROR]: Failed to find ${1:-default}'s IP" exit 1