SSHFS itself is a file system in user space (FUSE) that uses the SSH File Transfer Protocol (SFTP) to mount a remote file system. The sshfs command is a client tool for using SSHFS to mount a remote file system from another server locally on your machine.

Note: User space (or userland) is all operating system code that runs outside of the Kernel.

While not as performant as a local file system, sshfs is an easy way to work with files on another computer using local programs and tools. Best of all, sshfs can be used by non-privileged users on the local machine (in fact, it is recommended to not be root or to elevate oneโ€™s privileges while using sshfs), and it requires no special software on the remote machine other than SSH with SFTP enabledโ€”a common setup.

Installing sshfs

The sshfs tool is available from most distributionsโ€™ standard repositories and is most easily installed using that distributionโ€™s package manager. For Fedora, installing sshfs is as easy as: dnf install fuse-sshfs. On Debian-based systems, the package is simply sshfs.

Mounting a remote file system

Once sshfs is installed, mounting a remote file system safely over SSH is simple. According to the sshfs manual page (man sshfs), the syntax for the command is: 

sshfs [user@]host:[dir] mountpoint [options]

That syntax should look familiar to anyone who has used SSH or SCP before.

Letโ€™s take a look at sshfs in action. First, create (or select an existing) directory to use as a mount point. Note that the local user invoking the sshfs command must have write access to the mount point. As use of the root account is discouraged, that policy might make using ~/mnt preferable to /mnt. Then, it is just a matter of using the sshfs command to connect to the remote machine using your SSH credentials, and specifying which remote location to mount to the mount point:

# Create the mountpoint
[chris@marvin ~ ]$ mkdir ~/mnt

# Invoke SSHFS with your SSH credentials and the remote location to mount
[chris@marvin ~ ]$ sshfs chris@zaphod:/home/chris/Pictures ~/mnt

# Access the newly mounted filesystem
[chris@marvin ~ ]$ ls ~/mnt/
'Screenshot from 2019-11-17 19-34-34.png'

Note: Fun fact, sshfs doesnโ€™t expand ~ on a remote machine to the userโ€™s home directory.

The mounted file systems can be accessed and used the same way a local file system is, both from the command line or using other tools:

SSHFS example

When youโ€™re done with the remote file system, unmount it with the fusermount command:

# Unmount the remote FS
[chris@marvin ~ ]$ fusermount -u ~/mnt

Mount options

In most cases, the default sshfs command can be used as-is, but sshfs is far from a simple command. There are tons of options and flags that cover a variety of situations, including SSH and SFTP options, compression, etc. Check out the sshfs manual (man sshfs) for more details on what is available.

One of the most useful options, however, is reconnect, which allows the client to re-establish the connection to the remote system it is interrupted:

# Use "-o reconect" to allow the client to reconnect
[chris@marvin ~ ]$ sshfs chris@zaphod:/home/chris/Pictures ~/mnt -o reconnect

Mounting a remote file system on startup

The sshfs command can also be used in the client systemโ€™s /etc/fstab file to automatically mount the remote file system. Use the normal fstab syntax, including any options required, and use sshfs in place of the file system type:

# file: /etc/fstab
chris@zaphod:/home/chris/Pictures /home/chris/mnt sshfs

Note that using sshfs with fstab file mounting the file system must be done as root, so appropriate adjustments need to be made for SSH credentials, and adequate precautions must be taken.

Transport endpoint is not connected

You might receive a Transport endpoint is not connected error when the connection is interrupted (say, if the client machine changes networks, or is suspended). In this case, unmount the file system with the fusermount command, as described above:

[chris@marvin ~ ]$ ls ~/mnt
ls: cannot access '/home/chris/mnt': Transport endpoint is not connected
[chris@marvin ~ ]$ fusermount -u ~/mnt

Hopefully, this article gave you the basics needed to work with sshfs. It is a great tool for working with remote file systems securely over an encrypted SSH connection while mounted locally on your client computer. And as mentioned, thanks to sshfs being a FUSE file system, even unprivileged users can use it without requiring an administrator to set it up.

Want to try out Red Hat Enterprise Linux? Download it now for free.


์ €์ž ์†Œ๊ฐœ

Chris Collins is an SRE at Red Hat and a Community Moderator for Opensource.com. He is a container and container orchestration, DevOps, and automation evangelist, and will talk with anyone interested in those topics for far too long and with much enthusiasm.

UI_Icon-Red_Hat-Close-A-Black-RGB

์ฑ„๋„๋ณ„ ๊ฒ€์ƒ‰

automation icon

์˜คํ† ๋ฉ”์ด์…˜

๊ธฐ์ˆ , ํŒ€, ์ธํ”„๋ผ๋ฅผ ์œ„ํ•œ IT ์ž๋™ํ™” ์ตœ์‹  ๋™ํ–ฅ

AI icon

์ธ๊ณต์ง€๋Šฅ

๊ณ ๊ฐ์ด ์–ด๋””์„œ๋‚˜ AI ์›Œํฌ๋กœ๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•˜๋Š” ํ”Œ๋žซํผ ์—…๋ฐ์ดํŠธ

open hybrid cloud icon

์˜คํ”ˆ ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ํด๋ผ์šฐ๋“œ

ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ํด๋ผ์šฐ๋“œ๋กœ ๋”์šฑ ์œ ์—ฐํ•œ ๋ฏธ๋ž˜๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์„ธ์š”

security icon

๋ณด์•ˆ

ํ™˜๊ฒฝ๊ณผ ๊ธฐ์ˆ  ์ „๋ฐ˜์— ๊ฑธ์ณ ๋ฆฌ์Šคํฌ๋ฅผ ๊ฐ์†Œํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ตœ์‹  ์ •๋ณด

edge icon

์—ฃ์ง€ ์ปดํ“จํŒ…

์—ฃ์ง€์—์„œ์˜ ์šด์˜์„ ๋‹จ์ˆœํ™”ํ•˜๋Š” ํ”Œ๋žซํผ ์—…๋ฐ์ดํŠธ

Infrastructure icon

์ธํ”„๋ผ

์„ธ๊ณ„์ ์œผ๋กœ ์ธ์ •๋ฐ›์€ ๊ธฐ์—…์šฉ Linux ํ”Œ๋žซํผ์— ๋Œ€ํ•œ ์ตœ์‹  ์ •๋ณด

application development icon

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

๋ณต์žกํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ์†”๋ฃจ์…˜ ๋” ๋ณด๊ธฐ

Virtualization icon

๊ฐ€์ƒํ™”

์˜จํ”„๋ ˆ๋ฏธ์Šค์™€ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์—์„œ ์›Œํฌ๋กœ๋“œ๋ฅผ ์œ ์—ฐํ•˜๊ฒŒ ์šด์˜ํ•˜๊ธฐ ์œ„ํ•œ ์—”ํ„ฐํ”„๋ผ์ด์ฆˆ ๊ฐ€์ƒํ™”์˜ ๋ฏธ๋ž˜