zoukankan      html  css  js  c++  java
  • 校园网跨网段共享文件Samba+SSH

    Introduction

    This tutorial contains screenshots for the English version of Windows 10. Separate instructions for older versions of Windows are also available:

    To be able to mount a Windows share over SSH we will need

    • Administrator access to the local computer, including the ability to elevate privileges. If you don't know what I am talking about then stop reading right here.
    • One real or virtual network adapter, bound to the Client for Microsoft Networks driver.
      Normally you should already have such an adapter, as otherwise you would not be able to mount any Windows shares.
    • One real or virtual network adapter, NOT bound to the Client for Microsoft Networks driver.

    This part of the tutorial is split into the following steps:

      1. As most people do not have a spare real network adapter in their computer, we will add an extra virtual network adapter by installing the Microsoft KM-TEST Loopback Adapter.
      2. After that, the network adapter must be properly configured.
      3. Starting with Windows 10 update 1903, the Windows 10 feature "SMB 1.0" must be turned off.
      4. Furthermore, a few Windows system drivers need to be tweaked.
      5. Next, reboot Windows to verify that we've been able to grab port 445 and to see if the lanmanserver driver is up and running.
      6. Finally, we launch a special OpenSSH session and mount our Nikhef home directory.
    1. For those wishing to undo the above steps follow the instructions at the bottom of this tutorial.

    Windows 10 Upgrade woes

    Multiple persons have reported problems after a major Windows 10 upgrade (e.g. from 1803 to 1809). This is due mostly to the disappearance of the Microsoft KM-TEST Loopback Adapter and of the portproxy rule. In order to recover after a Windows 10 upgrade, try

    • Redo step 1 and reboot
    • If the adapter is still not present, run devmgmt.msc management console application and
      choose View->Show Hidden devices to see you can find the adapter again. If not, redo step 2.
    • Redo steps 3, 4 and 5.

    1. Installing the Loopback Adapter

    To install the Loopback adapter follow these steps:

    • Start the Add Hardware Wizard by either going Start->Settings->Control Panel->Add Hardware or by starting a console window with elevated (Administrator) privileges. In the console window type
        hdwwiz.exe
      
      The Hardware Wizard will come up:
      wizardStart
    • Click Next to continue:
      manualSelect
      Select Install the hardware that I manually select from a list and click Next.
    • Now you'll see:
      networkAdapters
      Select the entry Network adapters and click Next.
    • In the next screen
      msLoopback
      first select Microsoft from the list of Manufacturers and then select Microsoft KM-TEST Loopback Adapter from the list of Network Adapters. Finally, click Next once more.
    • Almost finished:
      readyToInstall
      This is your last chance to abort, otherwise, click Next.
    • After a while you should see:
      finished
      Click Finish to exit the Hardware Wizard.

    You are now ready to configure your newly installed Loopback adapter. Even though Windows might not ask you to, reboot anyways (heey, it's a Microsoft OS ;-)).
    From reports I've seen on the Internet a reboot is sometimes required for the loopback adapter to come up properly.

    2. Configuring the Loopback Adapter

    Now that your newly installed loopback adapter is up and running we must configure it properly:

    • Go to the Network Connections Center:
      NetworkConnections
    • Choose the loopback adapter (usually it is named something like "Local Area Connection #3") and right-click on it:
      ChooseAdapter
    • Choose Properties, after which a new window will appear
      loopProperties
      Make sure that
      • the entry Client for Microsoft Networks is NOT enabled, i.e. does not have a checkmark in front of it.
      • the entry File and Printer sharing for Microsoft Networks is NOT enabled, i.e. does not have a checkmark in front of it.
      • the entry Internet Protocol (TCP/IP) is enabled.
    • Select the entry Internet Protocol (TCP/IP), then click on Properties.
    • A new window will appear:
      loopPropertiesTCPIP
      Select Use the following IP address and fill in the 'IP address' and 'Subnet mask' as above.
      It is not necessary to fill in the 'Default gateway' or a 'DNS server'.
    • Click on Advanced to make the following window appear:
      loopPropertiesTCPIPAdv
      Deselect Automatic metric and fill in the value of 9999 as the 'Interface metric' as shown above.
    • Click on the WINS tab:
      loopPropertiesWINS
      and select Disable NetBIOS over TCP/IP.
    • Click on OK.
    • You are now back in the main 'TCP/IP Properties' screen. Click OK again.
    • You are now back in the main 'Loopback Properties' screen. Click Close.

    3. Disabling the "SMB 1.0" Windows feature

    Starting with Windows 10 update 1903 we need to disable the Windows feature SMB 1.0:

    • Go to the Control Panel->Programs->Programs and Features and select Turn Windows features on or off
    • A list of features pops up:
      FeatureSMB 1.0
      Scroll down and deselect the feature SMB 1.0/CIFS File Sharing support
    • Now close this control panel item.

    (Thanks to Michael Uhlenberg for pointing this out)

    4. Tweaking the 'LanmanServer' driver

    Now we first need to tweak a Windows system driver to overcome the thing that Microsoft broke. The root cause of the problem is that we need to access the file share using TCP port 445. However, when Windows 10 boots this port is grabbed by the system lanmanserver driver for all interfaces. By delaying the startup of the lanmanserver driver and by installing a portproxy rule we can circumvent this. This section explains how to do this:

    • Start a console window with elevated (Administrator) privileges.
    • First, we disable the automatic starting of the lanmanserver driver:
        sc config lanmanserver start= delayed-auto
      
      NOTE the space after the start= ! Also, if start= delayed-auto does not work then try start= demand
    • Make sure the IpHlpSvc driver is running at startup, as otherwise the portproxy rules are not executed:
        sc config iphlpsvc start= auto
      
      NOTE the space after the start= !
      Thanks to Michael Uhlenberg for pointing out this important driver.
    • Next we add a portproxy rule to reroute TCP port 445 to a port of our choosing. For this tutorial, I choose 44445:
        netsh interface portproxy add v4tov4 listenaddress=10.255.255.1 listenport=445
              connectaddress=10.255.255.1 connectport=44445
      
      IMPORTANT NOTES:
      • The listenaddress is the address of the Loopback adapter configured in the section earlier
      • The connectaddress must be identical to the listenaddress
      • Using listenaddress=127.0.0.1 does not work. Believe me, I've tried.

    If all went well you should see something like
    ConfigureConsole
    The portproxy rule is persistent, so there should be no need to repeat this step after a reboot.

    5. Reboot and verify

    Of course, now that we have disabled the automatic startup of the 'LanmanServer' driver we have to reboot Windows before proceeding.

    • Verify that the portproxy was applied successfully by checking the open ports on the system. Type in the command console
        netstat -an | find ":445 "
      
      You should see something like:
      Netstat
      If you see only '0.0.0.0:445' instead then the 'portproxy' rule was not applied correctly. Verify that the right 'portproxy' rule was used
         netsh interface portproxy show v4tov4
      
      and verify that the IpHlpSvc driver is running at Windows startup using
        sc query iphlpsvc
      
      Another reason for the 'port grabbing' to fail could be the LanmanWorkstation driver running at Windows startup. If so, try giving it the same treatment as LanmanServer. However, on the Windows 10 installations I tested this driver was running at system startup without causing any problems.
    • After Windows comes up and you have logged in, check the status of the 'lanmanserver' driver. Open a command console (no privilege elevation is required) and type
        sc query lanmanserver
      
      The 'LanmanServer' driver should be in the state Running. If it is not, then follow these steps to create a task using the Task Schedule to start it at system startup.

    On Windows 10 things are slightly different compared to Windows 7 and 8; it seems that Microsoft has read my tutorial and decided to provide a way to use local shares again ;-) !

    6. Putting it all together

    Now that we have configured both our loopback adapter we can put it all together by launching a special OpenSSH connection and mounting our Nikhef home directory as a Windows share:

    • Launch an OpenSSH session with some special port-forwarding rules and login on login2.nikhef.nl as normal. Open a Command console or terminal and type:
        ssh -v -N -n -L 10.255.255.1:44445:beuk.nikhef.nl:445 <Your-nikhef-userid>@login2.nikhef.nl
      
      Yes, there are lots of colons in that -L option but you need them all.
    • The first time you start the command with the special port forwarding rules, you will be (probably) be prompted by the Windows Defender Firewall that it has blocked some features:
      sshFirewall
      Allow access to at least Public networks by ticking the checkbox, then click on Allow access as otherwise the port-forwarding will not work.
    • Make sure port-forwarding is working properly by checking the (verbose) log:
      sshLog1
      Make sure the line
        debug1: Local connections to 10.255.255.1:44445 forwarded to remote address beuk.nikhef.nl:445
      
      is present before continuing.
    • Go to Start->Run and type \10.255.255.1user<Your-nikhef-userid>
    • In the Console window you should now see a line
        debug1: Connection to port 44445 forwarding to beuk.nikhef.nl:445 requested.
      
      as in the following screenshot:
      sshLog2
      If this is present then you can decrease the debug logging of the OpenSSH session by removing the -v option from the command line:
        ssh -N -n -L 10.255.255.1:44445:beuk.nikhef.nl:445 <Your-nikhef-userid>@login2.nikhef.nl
      
      Note If you carefully inspect the above screenshot then you will notice that I am using the (built-in) OpenSSH Authentication Agent in combination with an SSH public/private keypair to avoid having to type in my Nikhef password every time.
    • You will be prompted to authenticate yourself:
      networkLogin
      For the Username, fill in the domain NIKHEF followed by your Nikhef-Windows userid.
      For the Password, fill in your Nikhef-Windows password, which might be different from the password you use to log in on login2.nikhef.nl and press OK.
    • You should now see your Nikhef home directory in Windows Explorer!
    Congratulations!

    Mapping a network drive

    To make life even easier it might be handy to map a network drive to your Nikhef home directory:

    • Start Windows Explorer and choose Tools->Map Network Drive.
    • In the next screen, fill in:
      mapNetworkDrive
      • Choose an available drive letter.
      • Do NOT click on Browse but type in as the Folder name: \10.255.255.1user<Your-nikhef-userid>
      • Enable the checkbox in front of Connect using different credentials.
      • Now click on Finish.
    • In the next screen, fill in your Nikhef-Windows userid:
      networkLogin
      For the User name, fill in the domain NIKHEF followed by your Nikhef-Windows userid.
      For the Password, fill in your Nikhef-Windows password, which might be different from the password you use to log in on login.nikhef.nl and press OK.
    • In the next screen, click on Finish to complete the network drive mapping.
    • You should now see a new drive letter appear in the Folders tree-list in Windows Explorer. Click on it to verify that you are indeed viewing your Nikhef home directory.

    7. Control+Z! Undo! Undo!

    For those wishing to undo the CIFS-over-SSH trick follow these steps:

    1. Start a console window with elevated (Administrator) privileges.
    2. Restore the automatic startup of the lanmanserver driver by typing
        sc config lanmanserver start= auto
      
      NOTE the space after the start= !
    3. Remove the portproxy rule by typing
        netsh interface portproxy delete v4tov4 listenaddress=10.255.255.1 listenport=445
      
    4. Remove the firewall rule to allow SSH to do portforwarding from 10.255.255.1:
      • Go to the Windows Control Panel
      • Select System and Security, then Windows Defender Firewall
      • Select Allowed apps, and scroll down in the list to SSH, Telnet and Rlogin client and deselect the permissions
        firewallAllowedApps
        Then press OK
    5. Start a Device Manager by typing
        devmgmt.msc
      
      Expand the 'Network Adapters', right-click on Loopback adapter and select Uninstall.
    6. If necessary, use the 'Task Scheduler' from the 'Administrative Tasks' menu to delete the task 'Start LanmanServer driver'
    That's all, folks!
    reprint:https://www.nikhef.nl/~janjust/CifsOverSSH/Win10Loopback.html#Install

    Comments to Jan Just Keijser | lastmod = 26/01/2021 14:42

     
  • 相关阅读:
    微信分享功能开发代码整理
    js 完美兼容浏览器的复制功能
    linux 搭建svn服务器
    zendStudio安装Xdebug项目断点调试
    程序员开发常用英语词汇
    简单的一个远传采集并下载远传图片存储到本地示例
    form表单中经常用到的禁用获取值问题
    记录下url拼接的多条件筛选js
    better-scroll在vue中的使用
    移动端适配,引入lib-flexible,vue开发中将px转化为rem
  • 原文地址:https://www.cnblogs.com/1314h/p/15310036.html
Copyright © 2011-2022 走看看