If you are running Hyper-V on Windows 10 or Windows Server 2016, you probably know about a feature called PowerShell Direct. I also mentioned that PowerShell Direct is one of the 10 hidden features in Hyper-V you should know about. PowerShell Direct lets you remotely connect to a Windows Virtual Machine running on a Hyper-V host, without any network connection inside the VM. PowerShell Direct uses the Hyper-V VMBus to connect inside the Virtual Machine. Of course, this feature is convenient if you need it for automation and configuration for Virtual Machines. As this is great for Windows virtual machines, it does not work with Virtual Machines running Linux. In the latest Windows 10, Windows Server 1803 (RS4) and Windows Server 2019 (RS5) Insider Preview builds, Microsoft enabled a tool called HVC. HVC is a tool which allows you to do some command line VM management. HVC SSH is basically PowerShell Direct for Linux VMs.
This allows connecting to a Linux VM using SSH over the Hyper-V VMBus. You are also able to copy files inside a virtual machine using scp, similar to Copy-item -ToSession using PowerShell Direct. You can read more about PowerShell Direct on my blog or the Microsoft Doc pages.
How to connect to Linux VMs using SSH Direct
To connect to Linux VMs using SSH Direct (HVC) type hvc.exe into the command line or PowerShell. This will give you all the possible command options. Of course, SSH has to big configured inside the Linux virtual machine.
hvc ssh Thomas@VMNAME
To make this work, the SSH server inside the VM needs to be configured.
Final Thoughts
A pretty cool tool which will be available in the official releases of Windows 10 and Windows Server 1803, released this spring. Later this year this feature will also be included in Windows Server 2019. If you want to try it out today, give the Windows Insider Preview builds a spin.
Thanks to Ben Armstrong for pointing this out ;)
Tags: HVC, Hyper-V, Linux, Microsoft, OpenSSH, PowerShell, SSH, SSH Direct, SSH to Linux VM, SSH to VM, Virtual Machine, Virtualization, VM, Windows, Windows 10, Windows 10 Hyper-V, Windows Server, Windows Server 1803, Windows Server 2019, WSL Last modified: June 16, 2019
Hi,
I found your blog article and attempted to use hvc.exe to SSH to an Ubuntu Hyper-V VM
The host is Windows 10 1803, and the Guest is Ubuntu 18.04 downloaded from the MS Store via “Hyper-V Quick Create”, into which I have installed SSH.
I can use hvc.exe ssh user@vmName to connect from command prompt on host to the VM successfully, but only when the Ubuntu VM is connected to a v-switch which has management OS traffic enabled (i.e. host-to-guest networking enabled). Wireshark confirms that the SSH connection is occurring over the virtual network and not over the VMBus. As soon as I disconnect the VM from the vSwitch so that it is isolated, the hvc.exe ssh connection fails.
Do you have to do anything specific on either guest or host in order to get the Ubuntu VM to ‘listen’ for incoming SSH connections on the VMBus (as opposed to the TCP/IP stack).
Thx
P
@Paul: I have the same issue in a very similar setup. I’m doing ifconfig down on interfaces inside the VM and the SSH session terminates at one point. So it’s not going through vmbus for sure.
Thx for the reply @István.
@Thomas mentions in this blog post that “to make this work, the SSH server inside the VM needs to be configured”.
Other than ensuring that SSH is installed within the guest OS, I’m wondering whether there is some additional configuration of SSH that is required to allow it to ‘bind to’ or ‘listen’ on the VMBus, as opposed to a normal TCP socket.
@Paul I wouldn’t be surprised if this only works with Red Hat Enterprise Linux or CentOS as a guest. Vmbus Sockets is only supported on those according to Microsoft. I haven’t yet tried though.
As this is the 1st result in Google et al., I’ll put my understanding here, hoping it helps.
I had the same issue and digging into it, hvc.exe does not connect to ssh through VMBus: if you add ‘-v’ to see what’s going on under the hood, you can see that hvc.exe will try vsock (VMBus) 1st but will fallback to ip (TCP/IP) in case it does not work. As OpenSSH does not support vsock and only listen on TCP/IP, hvc.exe ends up using regular TCP/IP. If you do not have IP connectivity between HyperV and you VM, you are screwed.
I ended up writing a quick&dirty VMBus-to-TCP proxy to be able to connect to my Linux VM through VMBus using socat: https://github.com/bganne/hvnc
HTH
Hi,
I created a linux vm on a hyper-v host (Windows 2019).
On the Linux vm (CentOS) I have installed and configured the integration services and I have
tried to connect via SSH Direct (HVC nc vm-name -t vsock port(??)) but I got the following error:
“No connection could be made because the target machine actively refused it.”
Any suggestions?
Thx
Did you configure SSH Server within the Linux machine?
Hi Thomas,
thanks for the reply.
Yes, ssh over tcp/ip working properly.
Any other suggestions?
From PowerShell, `hvc id test_vm` correctly returns the VM’s ID and `hvc list` shows that the ‘test_vm’ `STATUS` is `running`.
Also, `hvc ssh` returns the ‘hvc ssh’ command usage options.
However, `hvc ssh root@test_vm` returns:
‘C:\Program’ is not recognized as an internal or external command, operable program or batch file.
Obviously, hvc is in the PATH variable, so what is going on here?
Hi Clayms
This is strange, which version of Windows 10 are you running?
Hi Thomas,
Version info below:
Major Minor Build Revision
—– —– —– ——–
10 0 17763 0
However, I suspect `hvc` is calling `ssh` from the the install of [OpenSSH](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse) which is installed in ‘C:\Program Files\OpenSSH\’ and that is what is causing the problem.
I don’t know why it only has a problem when I actually specify a username@vmname to ssh into.
How would I tell hvc to quote the path to the ssh executable?
@Paul, I finally figured this out. In answer to your question “Do you have to do anything specific on either guest or host in order to get the Ubuntu VM to ‘listen’ for incoming SSH connections on the VMBus (as opposed to the TCP/IP stack).” the answer is yes! The SSH service needs to know to listen on the VMBus as well as the TCP/IP stack. On my Ubuntu system I edited, /usr/lib/systemd/system/ssh.socket and added
ListenStream=vsock::22
after the existing line that said,
ListenStream=22
You then need to restart the ssh.socket service for the change to take effect.