SSHFS - the SSH File System


How to mount / umount a SFTP directory ? (aka SSHFS)

Table of contents

  • SFTP != FTPS
  • SFTP is what you do while using scp (and also WinSCP or FileZilla — in their respective SFTP modes (i.e. SSH-based file transfer), since they support other protocols as well).

For a quick / one-time use, consider using the SFTP client built in many file managers (Caja has one) by opening : sftp://sshServer/path/to/remote/dir


on sshServer :
provided sshd is up and running, there's nothing more to do
on sshClient :
apt install sshfs

mount and umount

mount :

  • As a non-root user
  • Should you need to map UID/GID between sshServer and sshClient, have a look at -o idmap=TYPE
interactively or with SSH keys
sshfs stuart@sshServer:/path/to/remote/dir /mount/point
password-based authentication (this solution is _a little_ dirty )
echo password | sshfs -o password_stdin stuart@sshServer:/path/to/remote/dir /mount/point

umount :

As a non-root user :
fusermount -u /mount/point

Save keystrokes with an extra /etc/fstab entry

SSH CLI options (ssh -o [options] ) can be turned into the corresponding /etc/fstab option :
ssh -o Compression=no,auto_cache
becomes (4th /etc/fstab field) :

It _may_ be possible to specify these settings in ~/.ssh/config for the corresponding host

Which gives :
stuart@sshServer:/path/to/remote/dir	/mount/point	fuse.sshfs,compression=no,auto_cache,noauto,user,default_permissions,uid=1000,gid=1000,noatime	0	0
  • You'll be able to mount the remote filesystem as usual :
    mount /mount/point
  • But umount requires sudo privileges :
    umount /mount/point
    umount: /mount/point: Permission denied
    This is because sshfs uses FUSE instead of the regular mount command (+ elevated privileges). As a result, you'll have to use the FUSE "umount command" (source) :
    fusermount -u /mount/point
When experimenting mount options, you may end up receiving errors such as :
read: Connection reset by peer
In such situation, add the debug and sshfs_debug options to increase verbosity (source).

Alternate solution : use this _VERY BASIC_ script :

#!/usr/bin/env bash

sshServer='mySshServer'	# full details in ~/.ssh/config

case "$1" in
		mount | grep -q "$mountPoint" && { echo 'Already mounted'; exit 1; } || sshfs -o idmap=user "$sshServer":"$sshRemoteDir" "$mountPoint"
		mount | grep -q "$mountPoint" || { echo 'Not mounted'; exit 1; } && fusermount -u "$mountPoint"
		echo 'wut?'
		exit 1

Improve network throughput

You may experience poor transfer speed with sshfs, and search engines will surely take you to pages suggesting to use the arcfour cipher type. However, arcfour is now considered unsafe and is disabled by default since OpenSSH 6.7 (2014-10-06) and not supported anymore since OpenSSH 7.6 (2017-10-03).
command-line line 0: Bad SSH2 cipher spec 'arcfour'.
	==> has been disabled by default in recent versions of SSH.
man -P 'less -p encryption' ssh_config

man -P 'less -p ciphers' ssh_config