1

I have two raspis set up running raspbian. One has an external HDD which I want to access with the other one over LAN. Is samba the way to go? I tried setting it up and I believe the server is running. But the client I don't get. In all those tutorials online it's always Windows as clients.

  1. Is Samba the way to go?
  2. If so, what's a good resource describing how to set up the client?
  3. If not, what else can I use?

Thanks

1

Answers:

  1. Yes - Samba is a good choice for what you want to do.

  2. There are many good resources for setting up Samba, here's one I created

  3. The main alternative for Samba is NFS. Each has its pros and cons. I use Samba because I'm more familiar with it. You can research the tradeoffs by doing a search like this one.

Caveats

There's a fair amount of effort required to get this done properly. We'll try to help if you hit snags, but you'll need to expend some effort as well. I recommend you use the command-line interface (CLI), but if you're uncomfortable with that, perhaps try finding a tutorial that uses the GUI.

Some details:

Here's a general outline to get this done:

  1. To check if Samba is installed:
$ apt-mark showmanual | grep samba
  1. Make sure your external HDD is mounted properly & has an entry in /etc/fstab. If not, read this.

  2. Once you have your drive mounted & Samba server configured, you may access it from any host that supports SMB (almost all do). If you want to access it from your 2nd RPi, you'll only need to install a client app; e.g. smbclient. You may install this as follows:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install smbclient

This sequence will ensure your system is up-to-date before you actually install smbclient. And there are other clients you can use on the RPi; you can search for them as follows:

apt-cache search smb
| improve this answer | |
  • Great directions, many thanks. There is no entry for the HDD in fstab on the first Rpi. I wonder how I can have my HDD mounted and accessible when there is no entry in fstab? Do I add it anyway? – Merkur3421 Apr 7 at 8:14
  • @Merkur3421: You must make the entry in /etc/fstab manually. Once again, read this. It's a rather long, detailed recipe, because I included all of my mistakes in it! Hopefully, you will learn from my mistakes & save a little time :) Let us know how that goes. – Seamus Apr 7 at 9:30
1

Another option for network file sharing is sshfs, which allows you to mount a remote directory locally over an encrypted connection.

It is very easy to configure and enabled by default on Raspbian if the ssh server is. To check, look for this line somewhere in /etc/sshd_config (that's sshd_config, not ssh_config); it is usually near the bottom:

Subsystem       sftp    /usr/lib/openssh/sftp-server

"sftp" is similar to sshfs but somewhat more awkward; they are both enabled by the same option. It should be uncommented (ie., no leading #). If you can't find it, add it at the bottom, and restart ssh: sudo systemctl restart ssh, then systemctl status ssh to make sure there were no issues. You can do this while you are logged in via ssh, as long as nothing goes wrong (in which case it may still be okay).

To use this, from another Pi (or anything with an ssh client1); you'll need credentials for the user, who must have permission to access the remote path:

sshfs pi@raspberrypi.local:/home/pi /mnt/pi2
                          ^ remote path after colon

The first bit is the same as an ssh login, user@hostname, but with a remote path prepended after a colon. The second arg is a local mount path. If this succeeds, /mnt/pi2 will map to /home/pi on the remote machine. You can use anything you like in either place (as long as they are real existing directories). You can also create multiple such mounts between the same hosts if you like, and in both directions.

If you want to allow non-root users access, they won't have it by default; see the allow_other option below.

If it fails and it is not clear why, you can use -vv as with ssh (ie., ssh -vv pi@...) to see some debugging output. You can also check /var/log/auth.log on the remote pi to see if there is a reason given there.

I use sshfs mounts constantly. The one between my workstation or laptop and NAS/general purpose LAN server (which isn't a pi anymore, but it was for a long time, and it is now something very similar running Debian) is done at boot and is incredibly reliable; I can even put the work machine to sleep, and the connection is still there when it wakes. The only time it goes down is when the LAN fails. I have similar connections to off site servers, and these are also ridiculously stable.

However, to achieve that may require a bit of tweaking. Here's what I use in /etc/ssh/sshd_config:

TCPKeepAlive yes
ClientAliveInterval 120
ClientAliveCountMax 15

You can find an explanation of these in man sshd_config. They also make for more stable logins.

When I mount the NAS connection, I use:

sshfs -o reconnect,ServerAliveInterval=45,ServerAliveCountMax=2 ...

Pretty sure this is fundamental to having the connection survive when the client goes to sleep (ie., goes offline and comes back a while later).

Some other useful options:

-o StrictHostKeyChecking=no,UserKnownHostsFile=/dev/null

You're probably already using this if you are using ssh on a LAN where the IP's aren't static, since otherwise ssh gripes about host keys for a given IP having changed. Don't use that for outside connections though.

-o allow_other,default_permissions

All the machines in my ecosystem are linux based with ext4 filesystems. This option makes permissions and such transparent; you have the normal permissions of your user. Without that, only root can access the mount.

SSHFS is encrypted, which makes it a bit slower than eg. NFS mounts, which I also use. When a Pi is involved, I get unencrypted NFS speeds of maybe 8-12 MB/s over wifi and 3-5 MB/s with sshfs. I still prefer sshfs for security (even on your own LAN it is worth being aware of all the other little things using it, especially if there are other people with their own devices).

If you are interested in NFS, I have a post about that here:

https://raspberrypi.stackexchange.com/a/75866/5538

(Your question is a tidier and more appropriately generalized, so I've closed the other one as a dupe.)


  1. There's a google chrome ssh plugin which works well and can do sshfs mounting, you'll have to look for instructions online (it is fairly simple). Also, it is not quite true that anything with an ssh client can do sshfs; on Android you are stuck with sftp.
| improve this answer | |
  • Interesting option! What OS clients have you used with this - any issues with any of them? – Seamus Apr 7 at 2:18
  • 1
    I only use linux and Android; you can't use it on Android (although you can use sftp). Apparently it is feasible from Windows w/ third party software: superuser.com/questions/1423371/… – goldilocks Apr 7 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.