Last active
November 14, 2015 23:18
-
-
Save alecthegeek/353fbaf5ad69025f60e6 to your computer and use it in GitHub Desktop.
ssh into a local Virtual Box Guest OS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ssh into a running Virtual Box guest machine | |
if [[ $# == 0 || $1 == -h || $1 == -? || $1 == --help ]] ; then | |
echo | |
echo usage: $(basename $0) '[<username>@]<machinename>' | |
echo | |
echo 'ssh into Virtual Box <machinename>, optionlly using <username>' | |
exit 1 | |
fi | |
if [[ $1 =~ (.+)@(.+) ]] ; then | |
ssh ${BASH_REMATCH[1]}@$(VBoxManage guestproperty get ${BASH_REMATCH[2]} "/VirtualBox/GuestInfo/Net/0/V4/IP"|cut -d " " -f 2) | |
else | |
ssh $(VBoxManage guestproperty get $1 "/VirtualBox/GuestInfo/Net/0/V4/IP"|cut -d " " -f 2) | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment