Last active
July 26, 2017 10:13
-
-
Save syaau/bde7b0a9c816bbb542076e49d36cd511 to your computer and use it in GitHub Desktop.
Shell script to start and ssh to a linux VBox VM
This file contains hidden or 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
| #!/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