Tech Tips

  1. Uncategorized
  2. 199 view

[Mac][VirtualBox][Ubuntu]How to connect to Ubuntu in Virtual Box using SSH

I followed the instructions.
  • Setting host-only adapter
  • Install openssh-server on Ubuntu
  • Setting static IP address on Ubuntu
  • Create start up script


Setting host-only adapter

Add hos-only adapter at Preferences… of VirtualBox menu.

Check host-only adapter’s IPaddress from right side icon.
Setting virtual machine’s network environment.

Install openssh-server on Ubuntu

Install oepnssh-server using apt-get.
$ sudo apt-get update
$ sudo apt-get install openssh-server

Set static IP address on Ubuntu

Fill in the address, gateway, netmask based on checked host-only IP address.
$ sudo vim /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth1
  iface eth1 inet static

Reboot after setting gives us to connect Ubuntu using ssh like this.
“ssh username@guest IP address”.

Make start-up script

Make start-up script and ssh connect script.
$ mkdir -p ~/myscript
$ vim ~/local-login

#! /bin/sh
isstarted=`ps aux | grep -c "GuestName"`
if [ $isstarted -eq 1 ]; then
  VBoxManage startvm GuestName -type vrdp
  sleep 5
  VBoxManage controlvm GuestName resume
ssh username@guest IP address
remain=`ps -e -o args | grep -c "^ssh.*GuestName"`
if [ $remain -eq 0 ]; then
  VBoxManage controlvm GuestName pause
  echo vm paused.
echo bye

$chmod 755 ~/myscript/local-login

GuestName part is virtual machine’s name、
username part is guest OS’s username、guest IP address part is guest OS’s IP address is set. And then, write the script path to .bash_profile.
export $PATH
How useful!

Uncategorized recent post

  1. Run Amazon FreeRTOS on M5Stack Core2 for AWS …

  2. Udacity Self-Driving Car Engineer Nanodegree …

  3. Install sbt 1.0.0 and run sample template

  4. Visualization of Neural Network and its Train…

  5. [Machine Learning]Created docker image includ…