Best way to mount remote folder
Solution 1
You can use plenty of things, among which, popular options are:
- NFS
- Samba / CIFS
- SSHFS
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=<your-samba-username>,password=<your-samba-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
).
Solution 2
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
.
# apt-get install fuse
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
.
# ls -l /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.
# apt-get install ssh
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.
Solution 3
In linux, you would choose for NFS (also check out the article on archwiki about it which may have applicable information for your distribution aswell). It has more advanced features then samba. If you need to lock (i.e. concurrent acces) files you should look into lockd aswell because nfs is stateless. However it is harder to configure than smb. I would suggest trying both samba and nfs to see which one suits your needs.
Solution 4
I have used both SFTP net drive and ExpanDrive in the past and I can tell you sshfs outperforms both without a question.
Related videos on Youtube
cjburkha
Updated on September 18, 2022Comments
-
cjburkha almost 2 years
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.
-
dchirikov over 11 yearsPossible copy of Download copy of file which updates on change
-
-
zrajm over 10 yearsI use my Pi as an NFS server with a disks with mostly my movies and other media (ie not system-critical stuff, not '/home/' or anything similar). NFS allows me to watch a movie without first having to copy it to the local drive, but when writing files to the NFS disk I prefer to use rsync. I've therefore mounted my NFS disks readonly, and write stuff over SSH (with rsync). This also stops me from accidentally rsyncing to an NFS mounted disk (which is very inefficient).
-
FutuToad over 10 years@zrajm how to you mount your disks on the pi?
-
zrajm over 10 years
arisu:/mnt/ytra /mnt/ytra nfs soft,ro,intr 0 2
-
thrig over 8 yearsSamba may confuse some unix applications, notably around permissions or what
stat()
returns, e.g. things that rely on thenlink
count which CIFS has no notion of. SSHFS I've been not much impressed with, as it ran context switches on the fileserver up mighty high, and did not support the necessary locking required by in-house programs. So, NFS... -
blendenzo over 7 yearsYou 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
-
amphibient over 6 yearsHey -- I tried to use your instructions (adjusting to
yum install fuse-sshfs.x86_64
) but when I didmodprobe fuse
it didn't create a fuse group for me. So when I didusermod -a -G fuse [your-user]
, I gotusermod: group 'fuse' does not exist
. can you assist ? thanks in advance -
amphibient over 6 years
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 ? -
amphibient over 6 yearsyes, I get
crw-rw-rw-. 1 root root 10, 229 Nov 21 15:32 /dev/fuse
-
Kvothe over 5 yearsAfter # apt-get install fuse-utils sshfs I get "Unable to locate package fuse-utils". Any idea why? (Ubuntu 18.04.01)
-
Kvothe over 5 years@Christopher, hmm not really. I mean it shows a lot of things (too many, but don't know how I would recognize anything equivalent to fuse-utils.) What am I supposed to do with this?
-
Kvothe over 5 years@Christopher, yes I did install sshfs and that succeeds, but I also need to install fuse-utils right?
-
Kvothe over 5 years@Christopher, thanks I will continue as if it worked then and see what happens. Note though that
# lsmod | grep fuse
and# modprobe fuse
both don't do anything (nor does the first if done after the second). -
Kvothe over 5 years@Christopher, you are right and I got it working. If you have time I still have one more question. After mounting there seems to be something wrong with permissions but I can't quite understand what. Before mounting I have permissions to the directory. Afterwards something changes. I can still access them through the terminal, but the browser (Nautilus) says I don't have permission anymore. Any idea what might be going on?
-
Hamedz almost 5 yearsIf the SSH connection drops for any reason you may lose your data. Hence,you’d want to save your work regularly as you work on files within an SSHFS mount.