How to Map a Network Drive Over SSH (SSHFS) in Windows: A Step-by-Step Guide

To mount a remote server’s file system as a network drive in Windows, using the secure SSH protocol is an efficient alternative to traditional SMB connections. This method allows secure access to files on a remote SSH server without needing to create a separate FTP (SFTP) connection. The SSHFS-Win client facilitates the process of mounting remote file systems via SSH.

You can obtain the SSHFS-Win MSI installer manually or through the built-in WinGet package manager with the following command:

winget install SSHFS-Win.SSHFS-Win

Once installed, you can map a remote folder as a network drive using Windows File Explorer. Right-click on This PC and select Map Network Drive. Assign a drive letter and set the UNC path to the remote directory in this format:

\prefix\user@host[!PORT][\PATH]

Where:

  • user is the account used for SSH authentication
  • host refers to the hostname or IP address of the remote server

You can use the following prefixes:

  • sshfs to map the user’s home directory
  • sshfs.r to mount the root directory of the remote computer
  • sshfs.k to map the user’s home directory using an SSH key
  • sshfs.kr to connect to the root directory with an SSH key

For instance, to mount the C:PS directory from a remote Windows host with the SSH server enabled, the command would be:

\sshfs.r<user>@<host>ps

On connecting, you’ll need to enter the password for the remote user. You have the option to save the password in Windows Credential Manager for future logins.

Alternatively, you can map a network drive from the command prompt using the net use command. To mount the /var/www directory from a Linux host, use:

net use W: \sshfs.r<user>@<host>varwww /user:sysops

This command will prompt for the user’s password each time. To persist the mapping across reboots, add the /persistent:yes option.

To avoid entering the password each time, you can store the credentials using:

cmdkey /add:<host> /user:<user> /pass:<password>

Multiple network drives can be connected simultaneously using the WinFsp.Np provider. To view connected drives, run:

net use

To delete a mapped network drive, use:

net use M: /delete

While it is possible to include the user’s password in plain text in the net use command, it is more secure to utilize SSH key authentication. To set this up, generate SSH keys on Windows and copy the public key to the authorized_keys file on the remote SSH server.

You can also automate the mapping of a network drive over SSH at Windows logon by creating a scheduled task that runs a PowerShell script. Here’s an example script:

$remoteUser = "admin"$remoteHost = "fs01.woshub.com"$remoteDir = "Install"$Drive = "M:"$privSSHKey = "C:secretfs01-id_rsa"cd 'C:Program FilesSSHFS-Winbin'$mountcmd = ".sshfs-win.exe svc sshfs.k$remoteUser@$remoteHost$remoteDir $Drive -IdentityFile=$privSSHKey"Invoke-Expression $mountcmd

For a more user-friendly experience, you can utilize graphical client tools like SSHFS-Win-Manager, which supports both password and key-based authentication for mapping remote directories.

Useful Links


Posted

in

by

Tags: