Terminal into Virtual Machines - atabegruslan/Notes GitHub Wiki

SSH into locally-hosted virtual machine

Setup virtual machine

Download Virtual Box: https://www.virtualbox.org/wiki/Downloads

Download and Install Ubuntu OS Image: https://ubuntu.com/download/desktop

Make sure u can use internet on virtual machine first (Chose a network setting that allows internet)

Install these essential functionalities:

sudo apt-get update
sudo apt-get install net-tools
sudo apt-get install openssh-server

Setup virtual machine's network

Option 1 - Bridge adapter

Make virtual machine on the same private network as your physical host machine:

What is bridge adapter:

How to use bridge adapter:

Option 2 - NAT & port forwarding (better)

You will need net-tools's ifconfig to find out the virtual machine's IP address.

On virtual machine, check and start the SSH service:

sudo service ssh status
sudo service ssh start

On host machine's terminal: ssh [email protected] -p2222 Use the 123456 password when prompted.

Setup SSH login

Physical machine's terminal: cat ~/.ssh/id_rsa.pub

In the terminal SSH'ed to the virtual machine:

echo "ssh-rsa…" >> /home/{user}/.ssh/authorized_keys

exit
ssh [email protected] -p2222 # Now you don't need password

Setup more users

In the terminal SSH'ed to the virtual machine:

sudo su

useradd pwuser -m -c "login with password" -G sudo -s /bin/bash
# Useful options of useradd are -c comment, -m to create his home directory and -s /bin/bash to define his shell.

passwd pwuser
# Enter password when prompted (eg: abcdef)

exit

ssh [email protected] -p2222
# Use the above set password: abcdef

Common issues and answers:


More