- SSHFS remote directory mounting syntax
- 6 Answers 6
- Notes:
- How To Use SSHFS to Mount Remote File Systems Over SSH
- Introduction
- Installing SSHFS
- On Ubuntu/Debian
- On Mac OSX
- On Windows
- Mounting the Remote File System
- Unmounting the Remote File System
- Permanently Mounting the Remote File System
- Using Win-SSHFS to Mount Remote File Systems on Windows
- Usage of the Remote Mount Point
- Mounting remote directory using sshfs
- Best way to mount remote folder
- 4 Answers 4
SSHFS remote directory mounting syntax
A Windows-10 64-bit PC was outfitted with:
- winfsp — msi download of latest release version or the Github project
- sshfs-win — msi download of latest release version or the Github project
A remote linux directory ( mydirectory ) is to be mounted to S:. The syntax is documented here.
«Baby steps» indicating preliminary success (non-Admin CLI):
however this does not mount mydirectory
Other user’s attempts to mount target directory have failed. Attempt from the Admin command-line failed:
System Error 67 has occured. The network name can not be found
for some reason, the syntax is such that I am required to type the username and password despite inputting the username: user@hostname
- What is the correct syntax to mount mydirectory to the S: drive?
- What diagnostics can be performed to determine corrective action?
6 Answers 6
In my Windows 10 mounting home directory of remote ssh server worked in user’s powershell using command
Note single dot at the end! Without the dot it did not work. For mounting root folder, use
The same works (but with different syntax) on Windows Explorer -> This PC -> Map network drive. In my system I had to enter the path with leading two backward slashes: for root
Note forward slashes here! You may need to mark «Use different credentials» and enter username / password in several subsequent dialogue boxes.
The net use command did not work for me, admin or not, PowerShell or CMD.
- Open Windows Explorer
- Find this pc , right-click on it
- Select map network drive
- Enter \\sshfs\bigfred@172.25.10.10/../../etc/blabber/mouth in Folder
- Check «Connect using different credentials».
- Hit Enter
Notes:
Windows 10 seems to be funny about permissions and folders here.
If you map \\sshfs\bigfred@172.25.10.10/ you’ll be stuck in your home folder and whatever sub folders it has. But you should be able to read and write.
If you map \\sshfs\bigfred@172.25.10.10/../.. You’ll be at the root folder, but will be stuck with whatever permissions your user has for the root for all folders. If you don’t have write access on the root folder, you won’t have write access on anything below it because Windows.
If you map \\sshfs\bigfred@172.27.10.10/../../etc/blabber/mouth You’ll have whatever permissions your user has on folder ‘mouth’, but you’ll be stuck in that folder, same as your home folder.
For newbs, adding /../.. is the equivalent of going into your home folder and typing cd ../.. Also the: is ignored/not needed in Windows mapping.
On Linux I can mount the remote root folder and operate as if I’m local to the machine; I can navigate to any folder.
On windows, there are quirks and restrictions you have to work around, so it’s better to mount the folder you need to work in. Inconvenient if you need access to multiple folders, but it works.
How To Use SSHFS to Mount Remote File Systems Over SSH
Last Validated on November 9, 2016 Originally Published on December 23, 2013
Introduction
In many cases it can become cumbersome to transfer files to and from a droplet. Imagine a development usage scenario where you are coding apps remotely and find yourself uploading a script repeatedly to your virtual server to test. This can become quite a hassle in a very short period of time. Luckily there is a way to mount your VPS file system to your local computer so you can make changes on the fly and treat your droplet as local storage. In this article, we will show you how to do exactly that.
Installing SSHFS
On Ubuntu/Debian
SSHFS is Linux based software that needs to be installed on your local computer. On Ubuntu and Debian based systems it can be installed through apt-get.
On Mac OSX
You can install SSHFS on Mac OSX. You will need to download FUSE and SSHFS from the osxfuse site
On Windows
To install SSHFS in Windows you will need to grab the latest win-sshfs package from the google code repository. A direct download link can be found below. After you have downloaded the package, double click to launch the installer. You may be prompted to download additional files, if so the installer will download the .NET Framework 4.0 and install it for you.
Mounting the Remote File System
The following instructions will work for both Ubuntu/Debian and OSX. Instructions for Windows systems can be found at the bottom of the tutorial.
To start we will need to create a local directory in which to mount the droplet’s file system.
Now we can use sshfs to mount the file system locally with the following command. If your VPS was created with a password login the following command will do the trick. You will be asked for your virtual server’s root password during this step.
If your droplet is configured for login via ssh key authorization, you will need to tell sshfs to use your public keys with the following command. You will be asked to enter the passphrase you used during the creation of your keys with ssh-keygen.
In case that you don’t have your SSH key stored under the root user, you would need to specify the full path to the private SSH key as follows:
Make sure to change the your_user part with your actual user.
Now you can work with files on your droplet as if it were a physical device attached to your local machine. For instance, if you move to the /mnt/droplet directory on your local machine you can create a file locally and the file will appear on your virtual server. Likewise, you can copy files into the /mnt/droplet folder and they will be uploaded to your droplet in the background.
It is important to note that this process provides only a temporary mount point to your droplet. If the virtual server or local machine is powered off or restarted, you will need to use the same process to mount it again.
Unmounting the Remote File System
When you no longer need the mount point you can simply unmount it with the command
Permanently Mounting the Remote File System
SSHFS also allows for setting up permanent mount points to remote file systems. This would set a mount point that would persist through restarts of both your local machine and droplets. In order to set up a permanent mount point, we will need to edit the /etc/fstab file on the local machine to automatically mount the file system each time the system is booted.
First we need to edit the /etc/fstab file with a text editor.
Scroll to the bottom of the file and add the following entry
Save the changes to /etc/fstab and reboot if necessary.
It should be noted that permanently mounting your VPS file system locally is a potential security risk. If your local machine is compromised it allows for a direct route to your droplet. Therefore it is not recommended to setup permanent mounts on production servers.
Using Win-SSHFS to Mount Remote File Systems on Windows
After launching the win-sshfs program, you will be presented with a graphical interface to make the process of mounting a remote file share simple.
Step 1: Click the Add button in the lower left corner of the window.
Step 2: Enter a name for the file share in the Drive Name field.
Step 3. Enter the IP of your droplet in the Host field.
Step 4. Enter your SSH port. (Leave as port 22 unless you have changed the SSH port manually).
Step 5. Enter your username in the Username field. (Unless you have set up user accounts manually you will enter root in this field).
Step 6. Enter your SSH password in the password field. (Note on Windows you will need to have your droplet configured for password logins rather than ssh-key-authentication).
Step 7. Enter your desired mount point in the Directory field. (Enter / to mount the file system from root. Likewise you can enter /var/www or
/ for your home directory).
Step 8. Select the drive letter you would like Windows to use for your droplets file system.
Step 9. Click the Mount button to connect to the droplet and mount the file system.
Now your virtual server’s file system will be available through My Computer as the drive letter you chose in step 8.
Usage of the Remote Mount Point
The remote mount behaves similarly to locally mounted storage: you are able to create, copy, move, edit, compress or perform any file system operations you would be able to do on the droplet, but you are not able to launch programs or scripts on the remote server.
One typical usage of this would be if you host a website on your VPS and need to make changes to the website on a regular basis. Mounting the file system locally allows you to launch whatever code editor, IDE, or text editor you wish to edit the site, and any changes you make will reflect on the virtual server as soon as they are made on your local machine.
Similarly, on droplets used for testing purposes of coding projects, it allows for much simpler code modifications which can be tested immediately without the need to modify the code locally as well as remotely (and eliminates the hassle of uploading new copies of files for small code changes).
Mounting remote directory using sshfs
SSHF provides a secure way to access remote machines on the fly via the Secure Shell File Transfer Protocol (SFTP). It stands for Secure Shell File System and it is a software developed for use on Linux distributions.
HOW TO USE SSHFS
1: Download and install the fuse-sshfs package
The SSHFS package is not included in any of the repositories on the Linux Operating System. You will have to download the rpm package for fuse-sshfs to your machine or you can use the yum command if you have access to an online repository.
After downloading the rpm package, go to the terminal of the local machine, migrate to the directory that has the downloaded package and then use the rpm command to install the rpm package for the sshfs
2: Create a mount point on the local machine
– On the machine where the SSHFS is installed, log in as root and create a mount point. I am going to call mine server22 and an ll command on that directory should show it is empty.
3: Mount the remote directory on the local machine
– Now mount the remote directory with the syntax
It should ask you for the password of the remote machine when you hit the enter button. Input the required password.
Now migrate to the mount point/directory, and do the “ll” command; if all is well, you should see the files in the mounted directory of the remote machine.
Most servers already support this protocol it is very easy to set up. On the client-side mounting, the file-system is as easy. We don’t have to do much configuration on the server-side. All you need is the remote server should have a working SSH server.
Best way to mount remote folder
I have two RasberryPi running debian wheezy and I would like to mount a folder from computer A on computer B.
What is the best (as in most efficient) way to do this?
I can do it via SMB, but that is for windows, I think there must be a better way to share across linux.
4 Answers 4
You can use plenty of things, among which, popular options are:
By ease-of-setup I think they would have to be put in this order (top: easiest)
SSHFS
Through FUSE, you can mount remote filesystems via ssh. I won’t cover how, as Cristopher has already very well explained that. Just note that, in order to mount the file automatically it will need a bit more of work.
Samba
It will allow you to use Windows and Unix machines to access the remote folder. If it’s not a big deal for you, then you won’t probably benefit from it. However, it’s easy to automount it on init (just input the apropriate values at /etc/fstab , including username= ,password= in the options column.
NFS
It will let you authenticate just via IP (no usernames thing = faster, only of use inside your non-hostile LAN) or via Kerberos Tickets (too painful for just two Raspberries; but useful in corporate environments).
As it has kernel mode support, it will run faster than sshfs. Besides, as there’s no encryption performed it will have a better throughput, and in the case of the tiny Raspberry ARM, it may make a difference.
Besides, it’s not so painful to setup simply you trust your network. You have automount support in /etc/fstab too, and you don’t have to put sensitive data (such as usernames or passwords), and if you have your usernames syncrhronized (same /etc/passwd and /etc/group files) you can use the usual POSIX permissions toolset ( chown , chgrp and chmod ).
SSHFS is wonderful. It can mount remote directories in a local directory with FUSE. The commands below use # to indicate that a command was executed as root , while $ indicates execution as a regular user. Because FUSE software is required, first make sure that it is available and running.
One of the lsmod and grep commands, below, can reveal if the software is loaded and ready for use. A result from either command indicates that fuse is available.
If there is no result from either command, try to load the kernel module without a reboot using modprobe and check again.
If loading the module fails, install the software with apt-get .
Check again after installation.
FUSE must be installed and running before continuing.
Check the permissions of /dev/fuse . The permissions should provide your regular user account with read and write access. Skip this part if you have determined that your regular user account already has read and write permission on /dev/fuse .
The output might be something like one of the following.
In 2013, my Debian created /dev/fuse with 0600 permissions, owner root , group owner fuse . I needed to let the fuse group use the device and to add my regular user account to the group, as shown below.
If the new group membership was required, log out and in again to become a member of the group.
Next, install ssh on both sides as follows.
This answer was written for Debian, but on Ubuntu 18.x at least, openssh-client , fuse , and a few other packages are a part of the Ubuntu sshfs package. The sshfs software is required on the client side, but it can be installed on both sides if desired. One of the package dependencies is fuse , but the installer skips over software that has already been installed.
With fuse and ssh available, and with permission to use the device, /dev/fuse , create a mount point for the remote file system; and, mount that remote filesystem locally as follows.
To mount a directory other than home, specify it after the colon.
To unmount, use fusermount .
If you have a Windows machine, it too can use SSHFS with win-sshfs. This software will «map a drive» with SSHFS, so that you can have a Windows drive letter that contains the remote directory.