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:
- https://www.youtube.com/watch?v=5BsShkcweIs
- https://www.techrepublic.com/blog/diy-it-guy/using-virtualbox-vms-on-your-networks-subnet/
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:
-
http://manpages.ubuntu.com/manpages/trusty/man8/adduser.8.html
-
https://askubuntu.com/questions/982395/where-to-find-password-for-users-created-in-ubuntu-16-04
-
https://websiteforstudents.com/how-to-list-all-user-accounts-on-ubuntu-16-04-18-04/
-
https://www.answertopia.com/ubuntu/managing-ubuntu-users-and-groups/
-
https://askubuntu.com/questions/612751/what-is-the-difference-between-the-groups-adm-and-admin
-
https://www.configserverfirewall.com/ubuntu-linux/add-user-to-docker-group-ubuntu/
More
- https://marekbosman.com/site/access-virtualbox-image-from-the-command-line
- https://unix.stackexchange.com/questions/566506/connect-to-virtualbox-gnu-linux-from-windows-10-via-ssh
- https://www.oracle.com/technical-resources/articles/it-infrastructure/admin-manage-vbox-cli.html
- https://superuser.com/questions/522713/command-line-tool-to-connect-to-a-virtualbox-guest-console
- https://www.virtualbox.org/manual/ch08.html#vboxmanage-common
- https://forums.virtualbox.org/viewtopic.php?t=41503