How to access SSH (SFTP) -based file systems on remote Linux servers from a Windows computer

botond published 2019. 02. 04., h - 13:45 time

Content

 

Introductory

If we operate or develop websites and have a Windows computer at home, it can be convenient to be able to directly access the remote storage from our computer in order to manage its content separately FTP vagy SSH, etc. without connections.

The basis and greatness of all of this is that if you have SSH access on any Linux-based computer (or even a Windows machine running an SSH server), the SSH connection also provides an SFTP channel that offers an FTP solution over the same encrypted line. This way, once you have access, you do not have to make any additional settings on the server side, but you can connect directly to any file transfer program that supports SFTP. Such a program is known, for example fileZilla file management program.

However, when using such programs, you must always connect to the destination and file operations can only be performed within the program.

Therefore, in this brief tutorial, we will look at a more convenient solution, where you mount a remote file system as a network drive permanently, which is immediately accessible at any time throughout your Windows system.

 

 

ingredient

This solution requires two small Windows-based programs:

First, download WinFSP from GitHub from this link and install it. I just have the winfsp-1.4.19016.msi version is available at the moment.

The program a FUSE It provides an API to bridge the file systems of different operating systems.

Then download it and install it SSHFS-Win program also in the appropriate version of our machine architecture from GitHub, which allows you to manage SSHFS file systems on Windows-based machines. I currently have sshfs-win-2.7.17334-x64.msi available in the 64 bit version.

Update (2023-03-31)
It's been a while since I wrote this review, so I checked these programs again. WinFsp already has the 2023 version, and the SSHFS-Win program currently has the 2021 version from the stable branch, but the 2021.1 Beta2 edition is already available in beta. In the section below, I will include pictures from their installation.

WinFsp

WinFsp installation

WinFsp installation

As you can see, this version already includes developer tools as well as the Cygwinalso adds FUSE file system support for .

WinFsp installation

WinFsp installation

SSHFS-Win

SSHFS-Win installation

SSHFS-Win installation

SSHFS-Win installation

SSHFS-Win installation

 

Mount a remote SSHFS file system

Once the two programs are installed, mounting a remote SSHFS file system is child's play. On your Windows computer, open the Start menu - Computer. Then right-click on the Computer group item in the left part of the window and a menu will appear, in which case select "Connect network drive ...". The settings panel will appear:

Windows 7 - Connecting a network drive

In the drop-down list under Drive, select the letter from which you want to access this file system from Windows.

For the Folder section we use this format:

\\SSHFS\felhasznalo@kiszolgalo

At the beginning, we indicate to the system that we want to configure a newly supported SSHFS file system. The user and server are access to the computer where we have SSH access.

With the option "Remount at login" set, it will automatically remount the remote file system after our machine is restarted, so it can be used completely as if it were a local drive, assuming that the remote machine is constantly accessible.

And the "Connect with different credentials" option is used to tell the system that the remote machine has a different username and password than the local machine, so that the system will not use your Windows login information when connecting.

Clicking the Finish button in the panel will bring up a login screen where you enter your username (which you pre-fill) and your password. You can also remember your login information here and you will not be prompted afterwards.

In case of a successful connection, the home directory structure of our SSH access will be opened:

Windows 7 - SSHFS remote file system mounted

Here I set up the SSH file system on my Debian 9 laptop. You can also see on the left that the system has permanently recorded the network drive, which can now be accessed from any program, e.g. Total Commander, other file managers, DOS command line, etc.

Use a unique SSH port number

If your server's SSH server is not a on standard SSH port 22 can be achieved but has a unique port setting, then append it after the server name separated by an exclamation mark. In this case, the syntax looks like this:

\\SSHFS\felhasznalo@kiszolgalo!port

Use a custom path

By default, the SSH protocol - including the SSHFS-Win program - enters the user's home directory, so our attached network drive will also be this directory. But what if we don't want to connect our home directory, but another directory, be it inside the home directory structure or outside it. With the SSHFS-Win program, this is not a problem either, let's see two examples of this.

If we want to mount a subdirectory within the home directory, the syntax is as follows:

\\SSHFS\felhasznalo@kiszolgalo\alkonyvtar\stb

So the point is that the SSHFS-Win program relative supports paths, so it handles paths differently than many other programs that start from the server's root directory. Here, the user's home directory is the starting point. Accordingly, if we want to mount a directory that is outside the user's home directory, we use the following syntax:

\\SSHFS\felhasznalo@kiszolgalo\..\..\mnt\stb

In this example, we mount the /mnt/stb directory on the server. Similarly, of course, any directory can be set, the main thing is that the user has at least read permission there. It's here, isn't it /home/ (Linux home directory structure), we had to double back to reach the root directory of the server.

Don't mix up the path markings used on Linux and Windows systems either! Linux uses "/" to denote the directory structure, while Windows uses "\". Accordingly, the SSHFS-Win program also uses the Windows directory markings, so we should enter the path with "\" signs if we want to use a unique path - different from our home directory.

Use a unique SSH port number and path

And finally, if we want to combine things, so we want to use a unique port number and route, we just need to connect the previous ones:

\\SSHFS\felhasznalo@kiszolgalo!port\relativ\eleresi\ut

Of course, the management of the route works in the same way in this case, if we want to define a route starting from the server root, then in accordance with the rules of relative addressing, go back as far as necessary by changing the "..\" directory. Of course, the path always starts with "\", but here this does not mean absolute access, but only part of the syntax. If not specified, it will throw an access error.

 

Disconnecting the Drive

If you no longer need the remote file system, you can simply disconnect the connection: Right-click on the network drive link on the left side of the panel, and then click "Disconnect" in the pop-up menu. This will disconnect the drive and close the connection.

In this case, of course, save and close any jobs you have opened from the remote drive beforehand so that unsaved data is not lost.

 

Conclusion

So with this very simple little solution, we can quickly and conveniently mount and use remote SSHFS file systems. Of course, there are other methods of data transmission that work on a shared basis, such as Samba Or the NFS shares. But these already require more complex settings.