Mapping a network drive over SSH in Windows
Submitted by ross on Mon, 06/25/2007 - 21:00
<!-- ckey="044D5739" -->I wanted a simpler way than OpenVPN to map a Windows drive to a remote system. One method I found is to use ssh (using Cygwin), or putty and forward port 139 to the remote system. In order to do that, we first need to install a "Loopback Adapter" and assign it an arbitrary IP address. Here are the steps involved:
- Install this official Microsoft patch: Programs that connect to IP addresses that are in the loopback address range may not work as you expect in Windows XP Service Pack 2
- Reboot
- Click "Start" / "Settings" / "Control Panel":
- Double-click "Add Hardware":
- Click "Next":
- Wait for this screen to go away:
- Select "Yes, I have already connected the hardware" and click "Next":
- Select "Add a new hardware device" and click "Next":
- Select "Install the hardware that I manually select from a list" and click "Next":
- Select "Network Adapters" and click "Next":
- Select "Microsoft":
- Select "Microsoft Loopback Adapter" and click "Next"::
- Click "Next":
- Click "Finish":
- Click "Start" / "Settings" / "Network Connections":
- Right-click "Local Area Connection x" and select "Properties":
- Uncheck all items but "Internet Protocol (TCP/IP)":
- Highlight "Internet Protocol (TCP/IP)" and click "Properties":
- Enter a "Local" IP address. Local IP addresses include 10.x.x.x, 172.16.x.x, and 192.168.x.x. In this example, we'll use 192.168.10.1. Then click "OK":

- Uncheck "Notify me when this connection has limited or no connectivity", and click "Close":
- For Samba based systems, you can connect to 127.0.0.1. For Windows based systems, you need to connect to the system's local, or public IP address. If you don't already know the remote system's local IP address, you can run ipconfig on it to discover it. For example, using ssh, you would type:
- Establish an ssh connection and port forward port 139 from our loopback adapter's IP address (192.168.10.1) to the remote system's IP address discovered above (192.168.1.101). For example, using ssh type:
C:\> ssh -L 192.168.10.1:139:192.168.1.101:139 remote.example.com
If you are using putty, type:
C:\Program Files\PuTTY> putty -ssh -L 192.168.10.1:139:192.168.1.101:139 remote.example.com
If you want, you can add the username and/or password to the command line:
C:\Program Files\PuTTY> putty -ssh -L 192.168.10.1:139:192.168.1.101:139 -l user -pw pass remote.example.com
- Run net use to map the network drive:
C:\> net use * \\192.168.10.1\sharename /user:"192.168.10.1\username" "password"
For example:
C:\> net use * \\192.168.10.1\c$ /user:"192.168.10.1\administrator" "admin password" Drive Z: is now connected to \\192.168.10.1\c$. The command completed successfully.
- To port forward 139 every time you run ssh, add the following to your ~/.ssh/config file:
- If you're using ssh, you can automatically establish this connection by installing and configuring the autossh package. This is non-trival, and beyond the scope of this tutorial. Good luck!

















C:\> ssh remote.example.com ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.1.101
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
If you are using putty, type:
C:\> cd /d "C:\Program Files\PuTTY" C:\Program Files\PuTTY> putty remote.example.com
enter your username, and password, and then type ipconfig:
$ ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.1.101
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
$ logout
Host remote.example.com LocalForward 192.168.10.1:139 192.168.1.101:139
Now, you can just type:
C:\> ssh remote.example.com
»
- ross's blog
- Login or register to post comments

Great Tutorial
Great tutorial, but a few questions.
was the local address you entered the 192.168.10.1 your actual ip address to your machine, or was that one you made up and the 192.168.1.101 your actual address to your machine. sorry I can usually follow these, but I dont think you stated your IP address in the tutorial.
techtutorial,
192.168.10.1 is the address I made up, and assigned to the new "loopback" network adapter. It could be any "local" address, such as 192.168.xxx.xxx, 10.xxx.xxx.xxx, or 172.16.xxx.xxx.
192.168.1.101 is the "local" IP address of the machine I am connecting to. This is the actual address of a real network adapter in the machine, and not a "loopback" address.
Hope that helps,
Ross
question
good tutorial!
but how does it work if the two computers are behind routers:
e.g.
my computer-my router-|....... Internet......|- my office router-my office computer
Do I need to do port forwarding in routers at both ends etc or is there a way to mount the drives between the two computers (one at home behind home router and another at office behind office router)
thanks in advance,
//sonny
Sanhay,
You will need to forward port 22 from the router to the workstation you wish to connect to.
If you wish to connect to more than one, you will need to map different ports. For example:
You can use any unused port you want for the source port, but numbers above 49152 are generally considered safe.
-Ross