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
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.
# lsmod | grep fuse $ grep -i fuse /lib/modules/$(uname -r)/modules.builtin
If there is no result from either command, try to load the kernel module without a reboot using modprobe and check again.
# modprobe fuse # lsmod fuse
If loading the module fails, install the software with apt-get .
Check again after installation.
# modprobe fuse # lsmod fuse
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.
crw-rw-rw- 1 root root (all users can read/write) crw------- 1 root fuse (only root can read/write) crw-rw---- 1 root fuse (root and members of fuse group can read/write)
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.
# usermod -aG fuse $your_regular_user_account # chmod 0660 /dev/fuse
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.
# Ubuntu 18.x: # apt-get install sshfs
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.
# mkdir /mnt/$directory_name # chown $your_user:$group /mnt/$directory_name/ $ sshfs $remote_username@$remote_server_name: /mnt/$directory_name/
To mount a directory other than home, specify it after the colon.
$ sshfs $remote_username@$remote_server_name:/remote/directory /mnt/$directory_name
To unmount, use fusermount .
fusermount -u /mnt/$directory_name
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.
You can significantly improve the performance speed of SSHFS by using additional options. See this article for more info and speed comparisons with NFS: admin-magazine.com/HPC/Articles/Sharing-Data-with-SSHFS
Hey — I tried to use your instructions (adjusting to yum install fuse-sshfs.x86_64 ) but when I did modprobe fuse it didn’t create a fuse group for me. So when I did usermod -a -G fuse [your-user] , I got usermod: group ‘fuse’ does not exist . can you assist ? thanks in advance
lsmod | grep fuse does return result and I do have /dev/fuse ,m which is owned by root. so you’re saying i’m okay without the group ?
After # apt-get install fuse-utils sshfs I get «Unable to locate package fuse-utils». Any idea why? (Ubuntu 18.04.01)
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)
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.
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.
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 ).
Mount remote directory using SSH
Now we’ll create a directory to mount the remote folder in.
I chose to create it in my home directory and call it remoteDir .
Now I ran the command to mount it (mount on home):
sshfs maythux@192.168.xx.xx:/home/maythuxServ/Mounted ~/remoteDir
I’m a little confused. in the sshfs command, I think that the mountpoint local directory is named remoteDir , and when I’m on the ssh serever, there is a dir /home/maythuxServ/Mounted that is not mounted locally, and I can not tell, or care, whether it’s mounted elsewhere?
I skipped some of these steps under 14.04 when I used the following guide: help.ubuntu.com/community/SSHFS
Configure ssh key-based authentication
Generate key pair on the local host.
Accept all sugestions with enter key.
Copy public key to the remote host:
$ ssh-copy-id -i .ssh/id_rsa.pub user@host
Install sshfs
Mount remote directory
$ sshfs user@host:/remote_directory /local_directory
Don’t try to add remote fs to /etc/fstab
Or don’t try to mount shares via /etc/rc.local .
In both cases it won’t work as the network is not available when init reads /etc/fstab.
Install AutoFS
Edit /etc/auto.master
Comment out the following lines
#+/etc/auto.master.d #+/etc/auto.master
Edit /etc/auto.sshfs
/local_directory -fstype=fuse,allow_other,IdentityFile=/local_private_key :sshfs\#user@remote_host\:/remote_directory
Remote user name is obligatory.
Start autofs in debug mode
$ sudo service autofs stop $ sudo automount -vf
Observe logs of the remote ssh server
$ ssh user@remote_server $ sudo tailf /var/log/secure
Check content of the local directory
You should see contents of the remote directory
Start autofs in normal mode
Stop AutoFS running in debug mode with CTRL-C .
Start AutoFS in normal mode
$ sudo service autofs start
Still good on Ubuntu 18.04. Used it to mount a directory from a Raspberry Pi 2 on a PC. When issuing sudo automount -vf , if you get 1 remaining in /- it is likely because you have already manually mounted the directory at step Mount remote directory . Rebooting should fix the issue.
Based on my experiments, explicitly creating the fuse group and adding your user to it is NOT required to mount ssh file system.
To summarize, here are the steps copied from this page:
$ sudo apt-get install sshfs
2.Create local mount point
3.Mount remote folder /remote/path to /home/johndoe/sshfs-path/
$ sshfs remoteuser@111.222.333.444:/remote/path /home/johndoe/sshfs-path/
$ fusermount -u /home/johndoe/sshfs-path/
sudo apt-get install sshfs
@: fuse.sshfs delay_connect,_netdev,user,idmap=user,transform_symlinks,identityfile=/home//.ssh/id_rsa,allow_other,default_permissions,rw,nosuid,nodev,uid=1000,gid=1000,nonempty 0 0
Although it is not answering your question exactly but I just wanted to mention that you can achieve the same goal using «sftp» as well. Just inside your file manager address bar type this command:
sftp://remoteuser@111.222.333.444/remote/path
An easy way to run sshfs mounts at startup is also by adding it to the root (or another user’s) crontab, like this:
@reboot sshfs remoteuser@111.222.333.444:/remote/path /home/johndoe/sshfs-path/
And if you need to add a delay, you can use:
@reboot sleep 60 && sshfs remoteuser@111.222.333.444:/remote/path /home/johndoe/sshfs-path/
I would like to warn that, it seems that by default only the user which set up the mount can access the remote directory.
I set up a remote directory, and create a crontab with sudo crontab -e . Later I found out the backup file didn’t write the remote directory at all. Then I found out that I could not cd into the remote disk as root ! So eventually I create the same task with crontab -e and everything works as I expected.