PreshBlog

sshfs – Mount a filesystem over SSH

by on Jul.04, 2007, under Linux, System Administration

I’ve decided to do a few posts about some of the cool tools and tricks I use most in my day to day usage of Linux, and I’ll start with sshfs, the SSH filesystem.

As the name might suggest, sshfs allows you to mount all or part of a remote system’s filesystem with nothing more than an SSH connection. Here’s some examples of how to use it.

If you don’t already have it, you’ll need to grab the FUSE (user-space filesystem) library (this only needs to be installed on the client, it’s not needed on the remote box you want to mount).

Once FUSE and sshfs are installed, mounting is simple.

This example will mount your home directory on a remote system to ~/foo:


sshfs foo.example.com: ~/foo

If you want to map another part of the filesystem, give the path after the colon, like:


sshfs foo.example.com:/var/log ~/foo-log

If you need to use a different username when connecting to the remote system, you can give it like this:


sshfs bob@foo.example.com:/ ~/foo

(the single slash at the end of that last example will make it mount the entire filesystem of the remote box). Of course, if you need to use a different username, in the long run it’ll be quicker to edit ~/.ssh/config and add a host section for the remote machine specifying the username to use, like:


Host foo.example.com
User bob

Of course, as the connection goes over SSH, it’s all secure.

To unmount when you’re done, use the standard fusermount -u mountpoint.

Hope you find this useful – let me know in the comments!


3 Comments for this entry

  • dom

    Your posts are very interesting to me (a relative newbie) and hence this post … I am trying to use sshfs to mount remote Maildirs securely. mutt works nicely but procmail does not: man procmail tells me that the diagnostics message “Unable to treat as directory” is because “Either the suffix on [the directory] would indicate that it should be an MH or maildir folder, or it was listed as an second folder into which to link, but it already exists and is not a directory”. Maybe I should not expect procmail to be able to operate over sshfs? Dominic

  • bigpresh

    @Dom:

    I see no real reason that it shouldn’t work over an sshfs mount?

    As far as I know sshfs mounts can mostly be treated like a normal filesystem. I’m not sure if file locking works properly over sshfs.

  • bryan

    how can I use sshfs with ftps? They block port 22 on my server, but I should be able to do it over ftps right? Any examples? They are hard to find!

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!