Skip to content

Instantly share code, notes, and snippets.

@syaau
Last active July 26, 2017 10:13
Show Gist options
  • Select an option

  • Save syaau/bde7b0a9c816bbb542076e49d36cd511 to your computer and use it in GitHub Desktop.

Select an option

Save syaau/bde7b0a9c816bbb542076e49d36cd511 to your computer and use it in GitHub Desktop.
Shell script to start and ssh to a linux VBox VM
#!/bin/bash
# Copy this script with run permission inside
# /usr/local/bin/vm-ubuntu
# Script to start and ssh to a VM on Virtual Box
# It starts the VM in headless mode (if not already started)
# This script assumes an Ubuntu Virtual Box named "Ubuntu"
# is already created with NAT network mode with host port
# 2222 forwarded to guest port 22 (127.0.0.1:2222 => 10.0.2.15:22)
# and consists of a user account named "ranjan"
# If a stop option is provided, stop the VM
if [ "$1" == "stop" ];then
VBoxManage controlvm Ubuntu poweroff
else
# An error is expected if the vbox is started, so ignore the
# error messages
VBoxManage startvm Ubuntu --type headless 2> /dev/null
# SSH to the VM with "ranjan"
ssh -p 2222 [email protected]
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment