"ssh" to a Windows Host
Every now and then, we may want to connect to a Windows host via ssh
.
Maybe it’s due to the frustration on connecting a Windows host via Remote Desktop Connection over a slow network.
Below is a way to ssh
(not really, actually) to a Windows host.
Step 0, install a Linux virtual machine in the Windows host
I use Oracle Virtual Box, and install a Ubuntu guest.
Step 1, share folders between the Windows host and the guest
Share the working folders between the Windows and the Ubuntu, so that these folders are accessible within the guest. Just google “virtualbox share folder”.
Step 2, configure the guest’s network settings
Choose NAT as the adapter type.
In the “Advanced” settings, add a port forwarding rule.
Choose an available port in the Windows host for “Host Port”.
Set “Guest Port” to 22
, which is the default port sshd listening on in the Ubuntu guest.
To find an available port in the Windows host, run netsh firewall show state
in the cmd.exe.
In my corporate network, for example, port 443 is allowed.
Step 3, make a connection
Open a ssh client in another machine, type the IP (or host name) of the Windows host as the hostname,
use the “Host Port” as the port, 443
in my case, for the ssh connection.
# my_user is the username of the Ubuntu guest VM
# 1.2.3.4 is the IP of the Windows host
# 443 is the opened port in the WIndows host
ssh my_user@1.2.3.4 -p 443
# use the hostname of the Windows machine is also ok
ssh my_user@my_win_desktop.my_corp.com -p 443
After the connection is up, we’re in the Ubuntu VM. Change the directory to one of the shared folders set up in step 1, and do the work. Much better user experience than Windows Remote Desktop when the network is slow.
Other ways
One way is to set the adapter as “Bridged Adapter” for the Ubuntu guest, so that the guest get an IP from the corporate network. Configure the port of sshd to a port the corporate network allows to connect from outside. One inconvenience is that sometimes the corporate network may assign a new IP for the guest after reboot.
Another way is to install the OpenSSH Server directly in the Windows host.
Browsers Ignore Change in Hosts File
I modified C:\Windows\System32\drivers\etc\hosts
for a local test.
However, the browser did not respect to the change in hosts file.
At last, I found it’s due to the proxy settings in my machine.
Change in hosts took effect once after I unchecked all proxy configuration in
Control Panel -> Internet Options -> Connections -> LAN settings.
If unfortunately in your network, connections are proxied by force (for example, in a corporate network), you can try to let the proxy bypass some domains by adding the domains into LAN settings -> Proxy server -> Advanced -> Exceptions.