Posts tagged virtualbox

VirtualBox SSH access
posted on 2014-07-05 19:08:08

When using virtual machines with VirtualBox, it can be helpful to have proper SSH access configured.

Theory up front

Virtualbox networking modes and Host Adapters

Since most people have trouble figuring this one out on themselves, some basics before, in case you do not just use 'NAT Mode'.

'Bridge Mode' of virtual box maps the physical NIC (network interface card) of your host OS (operating system) to the VNIC / virtual networking interface card / virtual adapter of your VM (virtual machine). That way all traffic is passed from extern to the VM directly, transparently to to the host OS. It will not have to fiddle with any packets flowing between VM and the/an internet.

'Host-only Mode' works on an IF (interface) of the host OS, similarily to the loopback device which is used by linux in case you have network-based application (i.e. TCP/IP based) running locally, on the localhost. The loopback interface sports the famous address but it can have any one from the subnet, which spans up to actually. Also you can have several loopback interfaces, in case you want to run several webservers locally and all on port 80. (I just made that example up from the top of my head, to provide a more plastic explanation, but I disgress.) The virtualbox Host-only adapter works similar in that, that virtualbox will use the virtual adapter to transfer all traffic among the vm's through this adapter.

There can be quite a bit more said, but just head over to the VirtualBox Manual and do the reading yourself, I am about to becoming lazy as this post grows quite a bit longer than I ever intented it to.

Virtual NIC's of the VM

This are the actual network cards being present in your virtual system.

To have internet as well as communication between host and guest (or among guests), you have to setup a two NIC's. To have two NIC's, you have to enable those in the settings of your VM, that is what the 'Adapter 1' to 'Adapter 4' tabs in the Network settings of the VM in question are for.

Short answer, if you do not have a NIC, you cannot assign ip's to it.

Of course, in the real world you can set several ip addresses on one NIC. Although I have not tried this, I doubt it to work since the VNIC's that virtualbox provides are different to each other, depending on the mode which they are set to I bet.

Actual IP configuration of the guest

Once the VNIC is enabled for your VM (which is like you just built in a physicalNIC into your desktop), you can configure it so linux will know about it.

So first you have to create a new entry in the networking config, followed by an ip configuration you make.

This should have you covered on the basics (so you got at least a small idea what you are actually doing next.), hopefully this will serve you good.

Without more words, easiest the ssh setup is done like this:

Setup VirtualBox

  1. Open the settings page of the VM in question from within virtualbox.
  2. Menupoint Network >> Tab Adapter 2.
  3. Checkbox Enable Network Adapter to create a new virtual Network Interface Card (NIC).
  4. Set 'Attached to:' to Host-only Adapter. The name of the adapter is not of interest, there just has to exist a vbox specific one already. If this is not the case, go to your virtualbox preferences (the ones of the hypervisor, not the ones of the individual vm's), choose "Network" in the left frame and then the tab "Host-only Networks". Add a network and edit the newly created adapter if you need a specific ip network or DHCP.
  5. Start the VM, and open a shell.
  6. $ ip addr and hit enter.
  7. Maybe you already have an ip then, otherwise you will have to set up networking with the ip network that is used in the vbox adapter in step 4. The one is a likely network, in case you did not change the default settings in step 4.
  8. Depending on if you have a RHEL-based distro in use (RHEL, CentOS, Fedora, ...), or Debian-based (Ubuntu, Debian), this step varies.

Setup guest VM, possibility one: static networking (recommended)


Open /etc/sysconfig/network-scripts/ifcfg-eth1 (Or whatever IF you looked up in step 6.) with root privileges and add the following code:


Fix IPADDR and DEVICE to the values in step 6.


Open /etc/network/interfaces as root and change/add this:

allow-hotplug eth1
iface eth1 inet static

As with the RHEL part, fix IF and IP accordingly, if these differ in step 6.

Setup guest VM, possibility two: dynamic networking (not recommended)

After you have set the additional NIC in your guest OS as described below, run ifup eth to activate the new interface and do dhclient eth1 afterwards to get an ip address from the dhcp server.


Open /etc/sysconfig/network-scripts/ifcfg-eth1 (Or whatever IF you looked up in step 6.) with root privileges and add the following code:



Open /etc/network/interfaces as root and change/add this:

allow-hotplug eth1
iface eth1 inet dhcp


For easiest usage, add a shorthand on your host OS into your ssh config. (/home/<username>/.ssh/config) If the file does not exist, create it.

Add this:

Host vbox
    User root #change this to the user as which you want to login
    StrictHostKeyChecking no

Which will make it possible to connect like this from your host OS:

$ ssh vbox

The strict hostkey check was turned off since you certainly know the machine you are connecting to and do not care when you use another vm with the same setting. (Which has very likely a different hostname.)

Of course, this step happens to be of little use if you use just DHCP ip's. Static network adresses are preferred as they will stay the same and you will not have to fix the config if you use several hosts and ip's get mixed up.

VirtualBox shared folders
posted on 2014-07-01 23:18:08

When using VirtualBox for toying around with VM's, you usually need a possibility to exchange files. This can either happen through version control, shared folders, Dropbox and the shared filehosters would be another option.

Here the shared folder approach will be described, in Ubuntu 14.04:

  1. Create a folder to be used on your host OS.
  2. Include the folder you just created in Virtualbox. Choose VM, Settings >> Shared Folders and add the new one. Transient is just temporary, you will very likely not want that. Choose a persistant approach, auto-mount and persistent. Plus the folder you just created in your Host OS. The 'label' (What you choose as 'Folder Name') you will need as mount position at the end.)
  3. Check your vbox version, Help >> About VirtualBox... will show it.
  4. Get the 'Guest Additions' ISO from here, the one fitting your vbox version.
  5. As root you have to prepare some things. In particular: apt-get install update, apt-get install upgrade, apt-get install dkms -y. This will make the changes to the kernel modules persistant across updates. The 'upgrade' part can maybe be skipped, IIRC.
  6. Mount the GuestAdditions ISO: Choose VM, Settings >> Storage >> choose IDE controller >> click on the CD icon on the right (not the one in the tree overview!).
  7. Either your VM will tell you to auto-run the ISO (easy).

Or you will have to use the supplied installer script (a little harder):

$ mkdir /mnt/iso
$ sudo mount /dev/cdrom /mnt/iso

Open the mounted ISO (cd to there), and do as root:

$ sh ./

If the mount fails due to 'bad superblock' or such, do cd /media && cd /cdrom && eject and reload the iso in the VirtualBox Manager. If the 'bad superblock' error still persists, this may be related to 14.04 or just me being dumb. Once all this is done, the folder chosen in VirtualBox needs to be mounted in the guest OS. sudo mkdir /mnt/share and sudo mount -t vboxsf <label-you-chose-in-step-2.> /mnt/share

So basically, there are several steps:

  • You need to have the Guest Additions installed in your guest OS.
  • In VirtualBox there has to be a linked folder to your host OS.
  • The folder linked in VirtualBox has to be mounted by its label into your guest OS.

Should be easy, but everytime I have to do it, it takes me ages. Or at least feels like.

This blog covers .csv, .htaccess, .pfx, .vmx, /etc/crypttab, /etc/network/interfaces, /etc/sudoers, /proc, 10.04, 14.04, AS, ASA, ControlPanel, DS1054Z, GPT, HWR, Hyper-V, IPSEC, KVM, LSI, LVM, LXC, MBR, MTU, MegaCli, PHP, PKI, R, RAID, S.M.A.R.T., SNMP, SSD, SSL, TLS, TRIM, VEEAM, VMware, VServer, VirtualBox, Virtuozzo, XenServer, acpi, adaptec, algorithm, ansible, apache, apachebench, apple, arcconf, arch, architecture, areca, arping, asa, asdm, awk, backup, bandit, bar, bash, benchmarking, binding, bitrate, blackarmor, blowfish, bochs, bond, bonding, booknotes, bootable, bsd, btrfs, buffer, c-states, cache, caching, ccl, centos, certificate, certtool, cgdisk, cheatsheet, chrome, chroot, cisco, clamav, cli, clp, clush, cluster, coleslaw, colorscheme, common lisp, console, container, containers, controller, cron, cryptsetup, csync2, cu, cups, cygwin, d-states, database, date, db2, dcfldd, dcim, dd, debian, debug, debugger, debugging, decimal, desktop, df, dhclient, dhcp, diff, dig, display manager, dm-crypt, dmesg, dmidecode, dns, docker, dos, drivers, dtrace, dtrace4linux, du, dynamictracing, e2fsck, eBPF, ebook, efi, egrep, emacs, encoding, env, error, ess, esx, esxcli, esxi, ethtool, evil, expect, exportfs, factory reset, factory_reset, factoryreset, fail2ban, fbsd, fedora, file, filesystem, find, fio, firewall, firmware, fish, flashrom, forensics, free, freebsd, freedos, fritzbox, fsck, fstrim, ftp, ftps, g-states, gentoo, ghostscript, git, git-filter-branch, github, gitolite, gnutls, gradle, grep, grml, grub, grub2, guacamole, hardware, haskell, hdd, hdparm, hellowor, hex, hexdump, history, howto, htop, htpasswd, http, httpd, https, i3, icmp, ifenslave, iftop, iis, imagemagick, imap, imaps, init, innoDB, inodes, intel, ioncube, ios, iostat, ip, iperf, iphone, ipmi, ipmitool, iproute2, ipsec, iptables, ipv6, irc, irssi, iw, iwconfig, iwlist, iwlwifi, jailbreak, jails, java, javascript, javaws, js, juniper, junit, kali, kde, kemp, kernel, keyremap, kill, kpartx, krypton, lacp, lamp, languages, ldap, ldapsearch, less, leviathan, liero, lightning, links, linux, linuxin3months, lisp, list, livedisk, lmctfy, loadbalancing, locale, log, logrotate, looback, loopback, losetup, lsblk, lsi, lsof, lsusb, lsyncd, luks, lvextend, lvm, lvm2, lvreduce, lxc, lxde, macbook, macro, magento, mailclient, mailing, mailq, manpages, markdown, mbr, mdadm, megacli, micro sd, microsoft, minicom, mkfs, mktemp, mod_pagespeed, mod_proxy, modbus, modprobe, mount, mouse, movement, mpstat, multitasking, myISAM, mysql, mysql 5.7, mysql workbench, mysqlcheck, mysqldump, nagios, nas, nat, nc, netfilter, networking, nfs, nginx, nmap, nocaps, nodejs, numberingsystem, numbers, od, onyx, opcode-cache, openVZ, openlierox, openssl, openvpn, openvswitch, openwrt, oracle linux, org-mode, os, oscilloscope, overview, parallel, parameter expansion, parted, partitioning, passwd, patch, pdf, performance, pfsense, php, php7, phpmyadmin, pi, pidgin, pidstat, pins, pkill, plesk, plugin, posix, postfix, postfixadmin, postgres, postgresql, poudriere, powershell, preview, profiling, prompt, proxmox, ps, puppet, pv, pvecm, pvresize, python, qemu, qemu-img, qm, qmrestore, quicklisp, r, racktables, raid, raspberry pi, raspberrypi, raspbian, rbpi, rdp, redhat, redirect, registry, requirements, resize2fs, rewrite, rewrites, rhel, rigol, roccat, routing, rs0485, rs232, rsync, s-states, s_client, samba, sar, sata, sbcl, scite, scp, screen, scripting, seafile, seagate, security, sed, serial, serial port, setup, sftp, sg300, shell, shopware, shortcuts, showmount, signals, slattach, slip, slow-query-log, smbclient, snmpget, snmpwalk, software RAID, software raid, softwareraid, sophos, spacemacs, spam, specification, speedport, spi, sqlite, squid, ssd, ssh, ssh-add, sshd, ssl, stats, storage, strace, stronswan, su, submodules, subzone, sudo, sudoers, sup, swaks, swap, switch, switching, synaptics, synergy, sysfs, systemd, systemtap, tar, tcpdump, tcsh, tee, telnet, terminal, terminator, testdisk, testing, throughput, tmux, todo, tomcat, top, tput, trafficshaping, ttl, tuning, tunnel, tunneling, typo3, uboot, ubuntu, ubuntu 16.04, udev, uefi, ulimit, uname, unetbootin, unit testing, upstart, uptime, usb, usbstick, utf8, utm, utm 220, ux305, vcs, vgchange, vim, vimdiff, virtualbox, virtualization, visual studio code, vlan, vmstat, vmware, vnc, vncviewer, voltage, vpn, vsphere, vzdump, w, w701, wakeonlan, wargames, web, webdav, weechat, wget, whois, wicd, wifi, windowmanager, windows, wine, wireshark, wpa, wpa_passphrase, wpa_supplicant, x2x, xfce, xfreerdp, xmodem, xterm, xxd, yum, zones, zsh

View posts from 2017-02, 2017-01, 2016-12, 2016-11, 2016-10, 2016-09, 2016-08, 2016-07, 2016-06, 2016-05, 2016-04, 2016-03, 2016-02, 2016-01, 2015-12, 2015-11, 2015-10, 2015-09, 2015-08, 2015-07, 2015-06, 2015-05, 2015-04, 2015-03, 2015-02, 2015-01, 2014-12, 2014-11, 2014-10, 2014-09, 2014-08, 2014-07, 2014-06, 2014-05, 2014-04, 2014-03, 2014-01, 2013-12, 2013-11, 2013-10

Unless otherwise credited all material Creative Commons License by sjas