When setting up the Hyper-V Guest hosts, I found it a little tricky and hard to find documentation on how to easily set these up, so I thought I would share how I got them into a configuration with the most simple process. With this setup you can also SSH into the Guest Host even if you do not have an IP address exposed on the Guest Network Adaptor.
To make thing even more simple I am using the pre-selected OS versions from the Hyper-V quick create options, but the steps should also work on other versions.
Linux Virtual Machine
In these steps below you will create an Linux Virtual Machine(VM) with the version ‘Ubuntu 18.04.3 LTS’
- Install and Open Hyper-V.
- Click Quick Create from the menu on the right.
- Select ‘
Ubuntu 18.04.3 LTS
‘ from the menu and create it. - Follow all the details from the wizard as requested with your chosen details.
- Once completed, start and login to your machine.
- Open the Terminal within the VM.
- Run the following commands
- Update installs
sudo apt-get update
- Install open ssh server
sudo apt-get install openssh-server
- Install linux azure
sudo apt-get install linux-azure
- start services by running the below repacing SERVICE-NAME for each of these sshd, ssh, hv-kvp-daemon.service
sudo systemctl start SERVICE-NAME
sudo systemctl status SERVICE-NAME - Allow SSH through the fire wall
sudo ufw allow ssh
- Update installs
Windows Virtual Machine
In these steps below you will create an Windows Virtual Machine(VM) with the version ‘Windows 10 dev environment’
- Install and Open Hyper-V
- Click Quick Create from the menu on the right
- Select
Windows 10 dev environment
from the menu and create it - Follow all the details from the wizard as requested.
- Once completed start and login to your machine
- Run these commands
- Install Open SSH
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
- Install Open SSH
SSH Keys
If you would like to login to your Virtual Machine then you will need to install the SSH keys.
You can find out how to generate keys and what keys you need from the SSH website. (https://www.ssh.com/ssh/keygen/)
Here is some more information on where to store the Public Keys once generated.
Public Key Store
On Linux, you can store them in the users directory in .ssh/authorized_keys
for example C:\Users\USERNAME\.ssh\authorized_keys
Unlike Linux there are one of two places you will need to add the keys. If you are admin add it to C:\ProgramData\ssh\administrators_authorized_keys
If you are not admin add it to C:\Users\USERNAME\.ssh\authorized_keys
Check If Admin
- Run lusrmgr.msc
- Select Groups
- Select Admin
- Check if you are in the group.
Once these tasks are completed you should be able to SSH into your Virtual Machines via the Hyper-V Console(HVC).
I have written about how to use this in a previous post ‘SSH to Hyper-V Virtual Machine using SSH.NET without IP Address‘. Although this targets the SSH.NET, you can use the commands from it to SSH from the Terminal.