Are you running Windows 10 as a host and want to connect to your Ubuntu VM? Are you using VirtualBox as a hosted hypervisor? If the answers to these questions are two yes, keep reading!
As you will see below, this technique is especially useful if you are using Ubuntu Server – which comes without a GUI – and want to avoid the pains of working on that terminal. For example, Page Up and Page Down didn’t work and the screen was too small. Even VirtualBox Guest Additions didn’t help solve the problem.
Here you find the list of steps from the creation of the VM to the SSH connection via PowerShell (the relative screenshots are under the list):
- Create a Ubuntu VM on VirtualBox (I’m using VirtualBox 6.1.26).
- Install Ubuntu Server 18.04.6 LTS in it (download the ISO from here by selecting “Server install image”).
- Start the VM and logon.
- Make sure that process sshd is running and listening on port 22 (s. Screenshot 1):
ps aux | grep sshd
sudo netstat -plant | grep :22
- Power off the VM.
- Open VirtualBox Manager, select the Ubuntu VM, and click on Settings. Click on Network, click on Advanced, click on Port Forwarding. Add a new port forwarding rule and click OK (s. Screenshot 2).
- PS: The Guest IP field is empty. With Guest IP = 10.0.2.15 (find yours by typing ifconfig in the terminal of the VM), the connection didn’t work.
- Start the VM again.
- Launch PowerShell on your host and type:
ssh pb@127.0.0.1 -p 10022
- The first time you connect, PowerShell will ask if you are sure that you want to connect and show you the ECDSA key fingerprint. You can double check it by typing this in the VM terminal:
ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub
(s. Screenshot 3). - Enter yes.
- Type again:
ssh pb@127.0.0.1 -p 10022
(if it does not work, restart PowerShell). - Enter you Ubuntu password. You will now see the Ubuntu welcome message (s. Screenshot 4). Now you are connected to your Ubuntu VM via PowerShell from your Windows 10 host. Congratulations! 🙂
I hope you liked this post. If you have any questions, feel free to leave a comment in the comment section. Never stop learning!