SSHFS: Mounting a remote file system over SSH (2024)

Posted: January 6, 2020 | | by Chris Collins (Sudoer alumni, Red Hat)

Image

SSHFS: Mounting a remote file system over SSH (1)

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 isa client tool for using SSHFSto mounta 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 sshfstool 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:

Image

SSHFS: Mounting a remote file system over SSH (2)

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 sshfscommand 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/fstabchris@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 ~/mntls: 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.

Topics: Linux Linux administration Security

SSHFS: Mounting a remote file system over SSH (2024)
Top Articles
Security Attacks and Countermeasures in Smart Homes
What You Should Know About SBA Prepayment Penalties | Pursuit
Dlnet Retiree Login
Faridpur Govt. Girls' High School, Faridpur Test Examination—2023; English : Paper II
Room Background For Zepeto
Nfr Daysheet
Hawkeye 2021 123Movies
Think Of As Similar Crossword
2022 Apple Trade P36
Osrs But Damage
270 West Michigan residents receive expert driver’s license restoration advice at last major Road to Restoration Clinic of the year
Does Publix Have Sephora Gift Cards
Erin Kate Dolan Twitter
George The Animal Steele Gif
Quadcitiesdaily
Big Lots Weekly Advertisem*nt
Euro Style Scrub Caps
O'Reilly Auto Parts - Mathis, TX - Nextdoor
Best Sports Bars In Schaumburg Il
Naya Padkar Gujarati News Paper
Skycurve Replacement Mat
Watertown Ford Quick Lane
Culver's.comsummerofsmiles
Geico Car Insurance Review 2024
Dr Seuss Star Bellied Sneetches Pdf
Cable Cove Whale Watching
Wolfwalkers 123Movies
Craftybase Coupon
Roseann Marie Messina · 15800 Detroit Ave, Suite D, Lakewood, OH 44107-3748 · Lay Midwife
950 Sqft 2 BHK Villa for sale in Devi Redhills Sirinium | Red Hills, Chennai | Property ID - 15334774
2430 Research Parkway
Bus Dublin : guide complet, tarifs et infos pratiques en 2024 !
Everything You Need to Know About NLE Choppa
Uhaul Park Merced
Truckers Report Forums
Indiana Wesleyan Transcripts
Ippa 番号
Polk County Released Inmates
Indiefoxx Deepfake
Henry Ford’s Greatest Achievements and Inventions - World History Edu
Nu Carnival Scenes
All Weapon Perks and Status Effects - Conan Exiles | Game...
Gw2 Support Specter
Phone Store On 91St Brown Deer
Lesson 5 Homework 4.5 Answer Key
Congruent Triangles Coloring Activity Dinosaur Answer Key
Automatic Vehicle Accident Detection and Messageing System – IJERT
German American Bank Owenton Ky
Makemkv Key April 2023
Deviantart Rwby
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 6341

Rating: 4.4 / 5 (55 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.