SAMBA/CIFS over SSH in Windows
- In short: create a VM in VMware Workstation Player or another similar virtualization software, install Ubuntu server, configure network in bridge mode, assign an static IP, create a tunnel to your samba server, from port 445 to port 445 too, and then in Windows 7/10 connect to
\\<your Ubuntu server local IP>\
- You can create a service to automate this tunnel at boot. Note: I don't know about compatibility with other Windows versions, but surely it will also work for Windows XP/8/11, if there is a virtualizer available to those systems.
- Note: for your convenience, if your computer is, for example, a laptop computer, and you will move in an out of your SAMBA server LAN, you can configure the Ubuntu server static IP to be the same as your local SAMBA server IP. Then, all your shortcuts in Windows will remain the same, whether you're inside the LAN (don't power on your VM inside the LAN!) or you're remotely connected via the tunnel.
Step by step guide on how to connect from Windows 7/10 to remote SAMBA server
- Note: As far as I know, having your client computer connected to the LAN via a wireless device, is incompatible with this setup. You have to be connected via ethernet, and don't forget, if your ethernet adapter is FastEthernet (100Mbps) your transfer rate with the SAMBA server will be limited to that speed (it will act as a bottleneck). So it's better if you have a Gigabit ethernet adapter (1Gbps).
The goal of this tutorial is to show you how to connect from a Windows 7 or Windows 10 system, to a remote SAMBA server, not in the same LAN, but in other LAN accesible via internet. The total troughtput is generally not limited by the VM or any other part of the proposed installation - I tried it and the bootleneck is the fiber internet connection - I have 300Mbps and the troughput, with big files, is ~36MB/s. Also know, before to start, that you will need some kind of server in which to configure DDNS - duckdns.org is a good option, I use from some time ago and it works perfectly. If your SAMBA server is always on, you probably can configure DDNS on it - for example, if it is Ubuntu Server-based it's easy. If you want to power on and off your SAMBA server from time to time, you may be interested in buying some router compatible with OpenWRT, and install OpenWRT on it, and you can have it as DDNS client. For the DDNS configuration, I recommend the Crontab configuration - it is well explained in duckdns.org
Before to start, let's concrete what information you will need before to start:
- The local IP of your LAN's router (usually 192.168.1.1).
- The DDNS address of the LAN in which the SAMBA server is installed.
- The TCP port of the SAMBA server's LAN's router, which is being redirected to your SAMBA server's SSH local address/port (the SSH port is usually 22). If there is no TCP port configured, you have to access that router and manually add a port of your choice.
- If you are going to open a TCP port, you need to know the SAMBA server's local IP too.
- A SAMBA server's user/password with sufficient permissions to connect via SSH and create a SSH tunnel.
- The SAMBA server's SAMBA user/password (the user database is the same for the Linux system and SAMBA, but the SAMBA password is independent from the Linux system password).
1. Install your hypervisor
In this example I'm using VMWare Workstation Player (free for non-commercial use). VMware Workstation Pro is also compatible. Oracle VM VirtualBox is also compatible (not 100% sure, but the important thing is that it has bridge-mode networking, and I know it has).
2. Create your Virtual Machine
The process is very straight-forward. The only important thing you need me to tell you, is the network configuration. Let me show you a screenshot of that step:
- Lets your Virtual Machine communicate to your router directly, without NAT or complicated network setups - and access the SAMBA server through internet.
- Lets the computers in your LAN communicate to your Virtual Machine (in the same subnet), and then, access to the SAMBA server via the tunnel you will create later.
Also, note that, when you see the following step:
I'm not sure about this, but I have experienced that if you tell VMWare what operating system you are going to install (being Ubuntu Server), it ran an assistant that autoconfigured the Ubuntu server installation. I never followed that way, but I imagine that may automatically configure your internet connection, and we want to configure an static local IP address.
3. Install Ubuntu Server in the Virtual Machine
- Note: you can install Ubuntu Desktop instead of Ubuntu Server, it will work too, but the resources that the Virtual Machine will consume will be notably higher. Ubuntu server is very lightweight and that is why I chose this kind of installation for this tutorial.
3.1. Starting Ubuntu server installation
From now on, I will only show the steps that are not obvious - It's hard to find the balance between the lack of information and the abundance of information, but I will do my best. In the steps that are not described, you can try to figure out yourself, and if you're not sure about what to do, just leave it as it is.
3.2. Configuring network
3.3. Other steps
3.4. SSH server
3.5. Other steps and finishing installation
4. Tunnel configuration and connection to the SAMBA share in Windows 7/10
- Note: (not password protected, please - if it's password protected, you will be forced to: either input it manually each time you create the tunnel, or type it in plain text in some file in your virtual machine)
If you didn't change the IP address, that will be the same as the screenshot (192.168.1.20). In Usuario/user, type your username from the section 3.3. Other steps. And in contraseña/password, type your password.
- Note for newbies: all text until the dollar sign is not the command. It's the prompt. The command starts at "sudo". Another note for newbies: "yourusername" should be substituted with your actual username, in the case of the first command "yourusername:yourusername" should be, for example, if your username is "mark", then "mark:mark". Also the file paths containing "yourusername" should be substituted, for example, by "/home/mark/..."
- Note: the -i option is to locate the private key. It should be assigned to its location. The -p option is the port that must be open in the SAMBA server side's router - assigning it to the local IP of the SAMBA server. The -l option is to indicate the user in the SAMBA server's side (the normal user, not the SAMBA user). You should know what user exists and has necessary rights, in that server. The -L option is the configuration of the SSH tunnel. myddnsdomainexample.duckdns.org should be substituted by your own DDNS domain.
- Note 2: the first time you run this command to connect to your SAMBA server, it's likely that you will see a caveat warning you about not known host and showing you information like the fingerprint and other stuff. This is normal and usually you should write yes, but I can't be responsible of your security matters.
As you can see, it's very fast! the bottleneck in this setup is my/SAMBA server's fiber connection, in my case 300Mbps in both sides.
5. Configuration of SSH tunnel as a service
- Note: If you didn't execute the ssh command (I mean you just executed the systemctl commands, but not the long ssh command in section 4), the service may not work correctly. Thus, you have to go back to that point of the tutorial and execute the command one time, so that you receive the security warning you usually receive the first time you connect to a remote host through ssh, and type "yes" or accept the host (I don't remember exactly, sorry!). Then, from that moment, the service you had created will start to work fine.
- Final note: Please, if you find any errors or typos in my explanations, please let me know in the comments. I have tried my best to write it correctly, and will be reviewing it sometimes, but you never know what errors you may encounter. Also if you need an explanation that you can't find a solution in google, and think that it should be included in the tutorial, please let me know in the comments. Cheers!
Comments
Post a Comment