Does any one know ssh -i equivalent for sshfs ? I want to use sshfs without promting for a password

5 Answers 5


The best solution would be ssh-agent as Zoredache suggests.

Another is to put your key in ~/.ssh/id_rsa, that way it will be detected automatically. (Use id_dsa for DSA keys.)

Yet another is ~/.ssh/config. Put something like this in it (see manual page of ssh_config for further details)

Host somebox.somedomain.tld
  User joe
  IdentityFile ~/key_for_somebox

Host *
  IdentityFile ~/key_for_everything_else
  • I discovered the awesome usefulness of the ssh config file not too long ago. It is very useful for multiple key setups.
    – jdizzle
    Jan 25, 2010 at 13:54
  • Note that if you must sudo sshfs then root can't see your home ~/.ssh/id_rsa
    – user246604
    Apr 27, 2020 at 16:23

Setup your system to use the SSH Agent and add your key to the agent. If you are using a recent Linux distro (ie Ubuntu and others) ssh-agent may already be setup for you. All you have to do type ssh-add key.


Another answer is sshfs -o IdentityFile=/home/me/.ssh/somekey.pem user@host:/path/ mnt/

Additionally, you will see people list another means of evoking sshfs:

sshfs -o ssh_command="ssh -i /home/me/.ssh/somekey.pem" user@host:/path/ mnt/

Though I will agree that ~/.ssh/config is the way to go.


Not quite what you asked for, but for the benefit of anyone else trying to connect to a server that doesn't support key authentication, you can use sshpass to type in your password for you even with sshfs.

For example, if you put something similar to this in /etc/fstab:

sshfs#username@host:/  /mnt/here   fuse   auto,ssh_command=sshpass\040-f\040/root/.ssh/host.password\040ssh  0  0

Then put the password in the filename specified in /etc/fstab:

echo 'secret' > /root/.ssh/host.password

Make sure you have installed sshpass:

pacman -S sshpass  # if you're using Arch Linux

Then it should work:

mount /mnt/here

You might need to ssh to the server once first to confirm its key, but after that this should work with no manual interaction.


For anyone looking for this in the future this worked for me ::

sshfs username@host:/yourpath  /yourpath  -o ssh_command='sshpass -p "yourpassword" ssh'


sshfs root@ /mnt/ -o ssh_command='sshpass -p 123456789 ssh'
  • 1
    Be warned that your password is now visible in whatever file you save this to. Aug 11, 2021 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy