Mount Drive via SSH with SSHFS

Linux Misc

If you need mount drive from linux or other system remotely, you can use SSH for enrypted traffic and SSHFS to mount the drive.
You will need to know Host IP or Host name, Port if it is not using 22 for SSH, Username and Password or SSH key.
Using Password appears to be easier, but not so secure because passwords are easier to guess.

First we need to install the WinFsp and SSHFS.
You can get it from Github, or use Winget in Windows Powershell. If winget is not available, this can be downloaded from Github or installed from Microsoft Store.

winget install WinFsp.WinFsp; winget install SSHFS-Win.SSHFS-Win

If you will use default port 22 and password that should be able to mount user home folder with just using this command in the File Explorer.

# using username and password for authentication, this will prompt you for login.
\\sshfs<username>@<SERVER NAME\
# using SSH key in your user home folder inside .ssh folder. 
# However you need to remove inheritance and all other users from accessing this folder and files inside.
# sshfs.kr will get you to root folder of remote server using SSH key
\\sshfs.kr<username>@<SERVER NAME>!<Port Number>\
# To generate SSH key you can use following:
ssh-keygen -t rsa -b 4096 -c "email, or some identifier here, if omitted hostname@username is used"
#more secure key is using ED25519
ssh-keygen -t ed25519 -C "your_email@example.com"

# CMD User Home Directory:          %homedrive%%homepath%
# Powershell User Home Directory:  $env:USERPROFILE

# you will need to copy the outputted SSH public key on remote server in ~/.ssh/authorized_keys
# To read the key you can run command for the key you created ( if you changed the name, use your file name):
type %homedrive%%homepath%\.ssh\id_ed25519.pub
type %homedrive%%homepath%\.ssh\id_rsa.pub

# You can also used built in function to copy SSH key, if you are able to sign in with password or you want add another SSH key.
ssh-copy-id -i %homedrive%%homepath%\.ssh\id_ed25519.pub username@remote-host -P <Port Number if not 22>
# In linux you would use ~/.ssh/id_ed25519.pub as path for the key.

# In powershell you can also use this way to copy the public key over on server:
# Get the public key file generated previously on your client
$authorizedKey = Get-Content -Path $env:USERPROFILE\.ssh\id_ed25519.pub
# Generate the PowerShell to be run remote that will copy the public key file generated previously on your client to the authorized_keys file on your server
$remotePowershell = "powershell New-Item -Force -ItemType Directory -Path $env:USERPROFILE\.ssh; Add-Content -Force -Path $env:USERPROFILE.sshauthorized_keys -Value '$authorizedKey'"

# Connect to your server and run the PowerShell using the $remotePowerShell variable
ssh username@domain1@contoso.com $remotePowershell

# I would recommend to enable SSH-Store on the windows, so you can easily use the ssh key without need of typing path for commands
# in Admin powershell you can enable the SSHD service or you can do it from GUI - Services
# By default the ssh-agent service is disabled. Configure it to start automatically.

# Make sure you're running as an Administrator.
Get-Service ssh-agent | Set-Service -StartupType Automatic
# Start the service
Start-Service ssh-agent

# This should return a status of Running
Get-Service ssh-agent

# Now load your key files into ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_rsa
ssh-add $env:USERPROFILE\.ssh\id_ed25519

Once you have the SSH key ready it will be easy to use the drive from linux on your windows computer.

You can mount the drive in File Explorer in This PC > Mount Drive and use the same path you would put to File Explorer path field.
Or you can use CMD (non admin, so it mounts to your profile):

net use \\sshfs.kr<username>@<hostname or  IP Address>!<Port Number if not 22>\<Path on remote server you want mount>\  <Mount Point Z:>
# For example connection on port 5000 using SSH key and mounting /home/ folder to mount point X:
net use \\sshfs.krsuperman@29.44.73.23!5000\home\ X:
# Mounting using username and password, (omitting the .k) and mounting user main home folder (omitting .r):
net use \\sshfsminiuser@example.com\ H:

For better user experiences on windows you can install SSHFS-WIN Manager  what is GUI interface for mounting drive:
https://github.com/evsar3/sshfs-win-manager
Download latest version: 
https://github.com/evsar3/sshfs-win-manager/releases/latest