Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Last active November 14, 2015 23:18
Show Gist options
  • Save alecthegeek/353fbaf5ad69025f60e6 to your computer and use it in GitHub Desktop.
Save alecthegeek/353fbaf5ad69025f60e6 to your computer and use it in GitHub Desktop.
ssh into a local Virtual Box Guest OS
#!/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