The server is listening on port '8765' and requires a SSH key for authentication.

I can mount the remote directory using this command:

sshfs -o idmap=user,port=8765 stephen@server:/export/usb2T /mnt/usb2T

The server recognizes my SSH public key.

I have seen that as an fstab entry for the standard SSH port this will be :

stephen@server:/export/inbox /mnt/inbox fuse.sshfs  defaults,_netdev  0  0 

But I will need to add the server's listening port and the client user's SSH public key.

How do I do that?


2 Answers 2


The entry in /etc/fstab you're looking for is:

Using the ,port=PORTNUMBER and ,IdentityFile=/root.ssh/id_rsa options:

  sshfs#USER@IP-ADDRESS:/export/inbox /mnt/inbox fuse.sshfs delay_connect,_netdev,user,IdentityFile=/root.ssh/id_rsa,idmap=user,allow_other,default_permissions,port=PORTNUMBER,uid=0,gid=0,rw,nosuid,nodev 0 0

Mounting directory through ssh with SSHFS from remote

  • By setting up SSH keys (as described above), you don't have to type your password when mounting. This will make mounting much simpler and can even be done using a script or automatically when you login to the local computer.
  • As with SSH, all traffic between the local computer and remote computer is encrypted.
  • If you are the admin on the local computer, you can configure the system to do this when the computer boots up so it will always be mounted. You need to modify /etc/fstab by adding a line like this (all on one line, though):
  • You'll also need to setup SSH keys to do this so you don't have to type in a password. Consult the SSHFS man page for an explanation of the options. If you find that the fstab line above isn't working correctly (causing an error message at boot), you can modify it to this (note the addition of noauto):

sshfs#USER@IP-ADDRESS: /export/inbox fuse defaults,user,noauto,
uid=einstein,gid=einstein,allow_other,IdentityFile=/home/alfred/.ssh/id_dsa 0 0 

sshfs#USER@IP-ADDRESS: /export/inbox fuse defaults,user,uid=USER,gid=USER,allow_other,IdentityFile=/home/USER/.ssh/id_dsa 0 0   

Mead's Guide to the Secure Shell (SSH)

How to mount sshfs remote directory in fstab

Automount sshfs using fstab without mount -a

SSHFS accepts many command-line options that you may want to check out. For example, if the SSH server on the remote computer was running on port 12345 instead of port 22, you would do this:

sshfs USER@IP-ADDRESS: /export/inbox -p PORTNUMBER

Here are the command-line options:

SSHFS options:

    equivalent to '-o port=PORT' 

equivalent to '-o compression=yes'
-F ssh_configfile
    specifies alternative ssh configuration file 

equivalent to '-o ssh_protocol=1'
-o reconnect
    reconnect to server 
-o delay_connect
    delay connection to server 
-o sshfs_sync
    synchronous writes 
-o no_readahead
    synchronous reads (no speculative readahead) 
-o sshfs_debug
    print some debugging information 
-o cache=BOOL
    enable caching {yes,no} (default: yes) 
-o cache_timeout=N
    sets timeout for caches in seconds (default: 20) 
-o cache_X_timeout=N
    sets timeout for {stat,dir,link} cache 
-o workaround=LIST
    colon separated list of workarounds 

    no workarounds enabled


    all workarounds enabled 

fix renaming to existing file (default: off)


set nodelay tcp flag in ssh (default: off)


fix truncate for old servers (default: off)


fix buffer fillup bug in server (default: on)

-o idmap=TYPE
    user/group ID mapping, possible types are: 

    no translation of the ID space (default)


    only translate UID of connecting user


    translate UIDs/GIDs based upon the contents of uidfile and gidfile 
-o uidfile=FILE
    file containing username:uid mappings for idmap=file 
-o gidfile=FILE
    file containing groupname:gid mappings for idmap=file 
-o nomap=TYPE
    with idmap=file, how to handle missing mappings 

    don't do any re-mapping


    return an error (default) 
-o ssh_command=CMD
    execute CMD instead of 'ssh' 
-o ssh_protocol=N
    ssh protocol to use (default: 2) 
-o sftp_server=SERV
    path to sftp server or subsystem (default: sftp) 
-o directport=PORT
    directly connect to PORT bypassing ssh -o slave communicate over stdin and stdout bypassing network 
-o transform_symlinks
    transform absolute symlinks to relative 
-o follow_symlinks
    follow symlinks on the server 
-o no_check_root
    don't check for existence of 'dir' on server 
-o password_stdin
    read password from stdin (only for pam_mount!) 
    ssh options (see man ssh_config) 



I want this sshfs mount to:

  1. happen only after network connection is achieved;
  2. for the files on the mount to be executable.

Pulling together the info provided in somethingSomething's excellent post along with the options required we have this:

stephen@server:/export/inbox /mnt/inbox fuse.sshfs x-systemd.automount,x-systemd.requires=network-online.target,_netdev,user,idmap=user,transform_symlinks,port=2314,identityfile=/home/stephen/.ssh/id_rsa,allow_other,default_permissions,uid=1000,gid=1000,exec 0 0

The additional options are :

  • x-systemd.automount creates an automount unit for systemd
  • x-systemd.requires=network-online.target attempts mount only after network connection is achieved
  • exec make files on the mounted drive executable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .