DeutschEspañolFrançaisItalianoNederlandsPortuguêsΕλληνικάРусскийالعربية中文(简体)中文(繁體)日本語한국어
 
Donate Bitcoins
Google
 
www smithii.com
 

Mapping a network drive over SSH in Windows

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:

  1. 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
     
  2. Reboot
     
  3. Click "Start" / "Settings" / "Control Panel":




  4. Double-click "Add Hardware":




  5. Click "Next":




  6. Wait for this screen to go away:




  7. Select "Yes, I have already connected the hardware" and click "Next":




  8. Select "Add a new hardware device" and click "Next":




  9. Select "Install the hardware that I manually select from a list" and click "Next":




  10. Select "Network Adapters" and click "Next":




  11. Select "Microsoft":




  12. Select "Microsoft Loopback Adapter" and click "Next"::




  13. Click "Next":




  14. Click "Finish":




  15. Click "Start" / "Settings" / "Network Connections":




  16. Right-click "Local Area Connection x" and select "Properties":




  17. Uncheck all items but "Internet Protocol (TCP/IP)":




  18. Highlight "Internet Protocol (TCP/IP)" and click "Properties":




  19. 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":




  20. Uncheck "Notify me when this connection has limited or no connectivity", and click "Close":




  21. 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:
  22. 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
    
  23. 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
    
  24. 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.
    
  25. To port forward 139 every time you run ssh, add the following to your ~/.ssh/config file:
  26. 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
    
  27. 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!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

error 53

I followed these instructions, but when I type "net use etc." I just get

"System error 53 has occurred.

The network path was not found. "

I used the same IP as in the tutorial : 192.168.10.1 for the loopback connection.
Remote ssh server happens to be : 192.168.178.105 on its LAN.

As there is a mini web server on port 6887 of 192.168.178.105, I also forward port 6887 to 192.168.178.105 for test purposes (it works, I can see the web page at 192.168.178.105:6887)

Yet port 139 forwarding does not seem to allow me to mount the C or D disk of 192.168.178.105 onto my machine.
Ideas, anyone ?

Berne.

Awesome article much better

Awesome article much better having drives network over a secure encrypted connection. I used to have a portable SSH client on floppy if you can believe that back in the very early 2000's so i could login to my servers from school on a secure connection. I just setup dcca diameter on my server to improve their performance. Now to get OpenSSL running.

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:

workstation source port destination port
=========== =========== ================
1           60122       22
2           60222       22
3           60322       22

You can use any unused port you want for the source port, but numbers above 49152 are generally considered safe.

-Ross

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
DeutschEspañolFrançaisItalianoNederlandsPortuguêsΕλληνικάРусскийالعربية中文(简体)中文(繁體)日本語한국어
 
Donate Bitcoins
Google
 
www smithii.com
 
Special thanks to Riester Rente Online for a generous donation!