GiselleSerate / myaliases

Useful shell aliases and functions.
6 stars 1 forks source link

sshfs on wsl2! #92

Open aryarm opened 3 years ago

aryarm commented 3 years ago

Thanks to WSL2, it's now finally possible to use SSHFS on Windows! This closes #91



sshopen

Mounts a remote file system over SSH on WSL. Lets you view and edit files on an ssh-accessible server as if they were on your Windows computer. Unlike sshfs, sshopen automatically handles the creation and subsequent cleanup of the mount directory.

prerequisites

  1. The remote server must have an entry in your ~/.ssh/config
  2. WSL2, not WSL1
  3. sshfs must be installed
  4. The user_allow_other config option must be uncommented in /etc/fuse.conf

    usage

    arg 1: the "Host" alias of the server, as specified in your ssh config
    arg 2 (optional): the path to the mount directory; defaults to arg1 in the current directory

    an example

    Let's mount our server, knuth.

    sshopen knuth

    After mounting the directory, you can also open it in Windows' File Explorer (using open() in .bash_nav).

    open knuth

    common issues

    • If the remote server lives behind an AnyConnect VPN, the sshopen command will fail. You should use openconnect to connect to the VPN before using sshopen
    • If sshfs gives error: fuse: device not found, try 'modprobe fuse' first, then you should use WSL2 and not WSL1
    • Depending on your network connection, sshopen might choke on large files. Consider using scp for such files, instead.
    • In order to reduce network usage, sshopen will only retrieve new files from the server every 15 minutes. If you want this to happen more frequently, just change the cache_timeout setting in the sshfs command.
    • The unmount will fail if any processes are still utilizing files in the mount, so you should close Windows File Explorer and any other applications before you close your terminal window. If the unmount fails, you can always just run the unmount commands manually:
      fusermount -u knuth
      rmdir knuth