Spiffberrypi | as a NAS + installing samba *

+ DEV SERVER

Raspberrypi as a NASInstall Samba

https://howchoo.com/pi/how-to-make-a-raspberry-pi-nas-device-with-samba

How to Build a Raspberry Pi NAS Using Samba

Setting up your own network storage device is super easy with a Raspberry Pi. All you need is an application called Samba and a few tweaks to the default settings. Before you know it, everyone on your network will have access to a custom Raspberry Pi NAS system. Everyone can share files with each other or even keep a private network folder for themselves.

If you're looking for something a little less technically-involved, skip to the end where we'll discuss OpenMediaVault and NAS4Free.

Table of Contents

JUMP TO STEP:

  1. Update Raspberry Pi OS
  2. Install Samba
  3. Create storage directories
  4. Enable authentication prompt
  5. Adjust private storage permissions
  6. Adjust public storage permissions
  7. Save and restart Samba
  8. Add user to Samba
  9. How to add additional storage to your Pi (optional)
  10. Connect to the NAS
  11. Alternatives to Samba: OpenMediaVault and NAS4Free

Update Raspberry Pi OS

Before we download anything, we need to start with a fresh update. In this guide, I'm using a Raspberry 3 B+ with Raspberry Pi OS (formerly Raspbian) installed. Be sure to update your OS to the latest version. Visit our guide on how to update to the latest version of Raspberry Pi OS.

How to Install Raspberry Pi OS on Your Raspberry PiGet the new official Raspberry Pi OS on your Pi.

Install Samba

Once everything is up to date, it might be a good idea to restart your Raspberry Pi. You can use the following command to restart:

sudo reboot

After a fresh update and restart, we're ready to get started. Run the following command to install Samba on your Pi.

sudo apt install samba samba-common-bin

Create storage directories

Samba will need a place to store our files on the network. Therefor we will create our own directories and point Samba to them. Use the following commands to create both a private and public directory location.

Note: My example places the folders under the /home/ directory. You may find another location is suitable for your NAS structure.

sudo mkdir /home/storage
sudo mkdir /home/storage/public

These directories require special permissions to function properly. Use the following commands to set the permissions.

sudo chown -R root:users /home/storage/public
sudo chmod -R ug=rwx,o=rx /home/storage/public

Enable authentication prompt

Enable authentication prompt

If you want to enable a login prompt for your storage device, open the following file.

sudo nano /etc/samba/smb.conf

Look for this line:

##### Authentication #####

Beneath it, add the following string:

security = user

Leave this file open, we will be using it for the next couple of steps.

Adjust private storage permissions

Adjust private storage permissions

This step will allow for write permissions to the private storage directory. Using the same file from the previous step, look for a section titled:

[homes]

Change the read only section to reflect:

read only = no

Adjust public storage permissions

Adjust public storage permissions

This step will set access permissions for the public storage directory. Using the same file from the previous steps, scroll to very bottom and enter the following:

[public] 
comment = public storage 
path = /home/storage/public 
valid users = @users 
force group = users 
create mask = 0660 
directory mask = 0771 
read only = no

Save and restart Samba

After adjusting all of the permission settings, we will need to save this file. Press ctrl + x to open the exit prompt. When asked to save the document, press Y and enter.

Restart Samba with the following command:

sudo /etc/init.d/samba restart


sudo /etc/init.d/smbd restart - doesn't work?

Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g.

service smbd restart

Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the stop(8) and then start(8) utilities, e.g. stop smbd ; start smbd. The restart(8) utility is also available.


smbd stop/waiting

smbd start/running, process 7831

So the commands to start/stop samba:

sudo stop smbd
sudo start smbd
For systemd related systems (ie. Ubuntu 16.04):

systemctl start smbd.service

THIS WORKED FOR ME
service smbd restart


Add user to Samba

If you'd like to add a user to Samba, run the following command:

sudo smbpasswd -a pi

In my example, I'm adding the user "Pi". Follow the prompts from Samba to set a password for the NAS.

How to add additional storage to your Pi (optional)

You can provide extra storage to your NAS device by adding a usb thumbdrive or even harddrive. Plug in the device and use the following command to find its name:

dmesg

If this is the first and only usb storage device, it will probably be named "sda1". Whichever device you'd like to add to the NAS, take note of the name.

Format the drive

If you haven't already, you will need to format the drive with a Linux file system. Use the following code to format the drive, replacing "sda1" with the appropriate drive name.

umount /dev/sda1
sudo mkfs.ext4 /dev/sda1
Create a directory for the additional drive

Create a directory for the drive and set appropriate permissions with the following code:

sudo mkdir /home/storage/public/disk1
sudo chown -R root:users /home/storage/public/disk1
sudo chmod -R ug=rwx,o=rx /home/storage/public/dis
Enable drive mount on reboot

Rebooting your Pi will cause the drive to dismount. You can set up the pi to always mount the additional device on startup. Run the following command:

sudo nano /etc/fstab

Add the following line to the bottom of the file for each drive you want to mount. Replace "sda1" with the name of the respective drive.

/dev/sda1 /home/storage/public/disk1 auto noatime,nofail 0 0

Connect to the NAS

Connect to the NAS

This is the easiest part. Congratulations! Your NAS Pi device should now be accessible on your network. It's time to drag and drop files to your heart's content. If you're using a Windows device, the following path will open the NAS from a run window.

Note: My Pi is named "raspberrypi". You will need to adjust the example to reflect the name of your Pi.

Public folder access:

\\raspberrypi\public

Private folder access (for a user named pi):

\\raspberrypi\pi

 

Alternatives to Samba: OpenMediaVault and NAS4Free

If you don't want to go the Samba route, there are two applications worth mentioning, and both are relatively simple to install.

OpenMediaVault and NAS4Free are available for free, and they install easily from a disk image.

Download the image for either, then write the image to your SD card. I'd recommend checking out Etcher to do this, since it's available for Windows/Mac/Linux and simple to use.

Pop that SD card into your Raspberry Pi and watch as they install automatically. Finish configuring with your IP address and voila!

https://www.thedigitalpictureframe.com/installing-samba-on-your-raspberry-pi-buster-and-optimizing-it-for-macos-computers/#:~:text=SMB%203%20(the%20latest%20version,Use%20SAMBA%20instead.

Installing Samba on your Raspberry Pi and optimizing it for macOS computers

Last updated December 28, 2020 / By Wolfgang Männel

File sharing is one of the basic functionalities of an operating system. But if you install Raspberry Pi OS on your Raspberry Pi, you still need to add the Samba software to make your Pi accessible in a Windows/macOS or Linux environment.

Although this is relatively straight forward, there are several things that have changed over time, and many tutorials on the web are outdated in this regard. After all, Samba has been around since 1992 to provide file and print services to all manner of SMB/CIFS clients.

The recent Raspberry Pi OS release and Apple’s shift from AFP to SMB has also brought about some changes, and this tutorial will explain to you primarily how to optimize your Raspberry Pi Samba setup for macOS computers in your network. All this will, of course, also work for connected Windows and Linux computers.

Preparation

You have installed the latest “Raspberry Pi OS” version on your Pi and are connected to the Internet. If you don’t know how to do that, you can look here.

I also assume that you are connected to your Raspberry Pi via ssh in a Terminal window.

Alternatively, you can do the same on your Raspberry Pi if you have a monitor and a keyboard connected to it. As many Pis are used as headless systems, ssh’ing into the Pi has become a popular way.

Before you install new packages, you should always run a system update with

sudo apt update && sudo apt upgrade -y

Samba works with all Raspberry Pi models, but file sharing is much faster with the Raspberry Pi 3 (theoretically Gigabit but hampered by the USB 2.0 bus speed resulting in ~224 Mbps) and especially with the Pi 4 and its Gigabit ethernet port (over 900 Mbps).

If you expect decent file-sharing performance from your Raspberry Pi, get a Model 4 with 2 or 4 GB of RAM.

If you only need the occasional file exchange like for a digital picture frame, then the maximum speed doesn’t matter that much.

AFP, Bonjour and Avahi

As I mentioned earlier, there are many Raspberry Pi networking tutorials on the web that suggest installing several packages that you don’t need anymore. Let’s go through the most often mentioned ones.

Apple originally used AFP (Apple Filing Protocol) but moved over to SAMBA (SMB) in macOS 10.9 Mavericks released in 2016. You will still find many tutorials about installing AFP with Netatalk, but I don’t see any reason to stick with legacy technology.

SMB 3 (the latest version) is faster than AFP and provides all features you would need for your Mac (like Time Machine compatibility). Conclusion: Forget about installing AFP on your Pi. Use SAMBA instead.

Bonjour is Apple’s wonderful technology that automatically locates and displays devices and services like computers, file shares, or printers that are available on a network. It is built in macOS but also available for Microsoft Windows. To allow the Raspberry Pi to propagate itself across a network and to be recognized by Bonjour, you needed to install the Avahi package separately. The latest Raspberry Pi OS version includes this right out of the box, so no need for installing it.

To summarize: All you need for Raspberry Pi file sharing is SAMBA.

Installing Samba

In the Terminal window enter

sudo apt install samba -y

When this window comes up, choose “No”.

Installing Samba on your Raspberry Pi and optimizing it for macOS computers 3

If you want to access other network computers from your Raspberry Pi, e.g., when you use it as a desktop computer, you will also need to install the CIFS tools. They were initially part of the Samba package but later split into their own package.

For an application like a digital picture frame where you don’t need to see other computers but just be visible in the network yourself, you won’t need to install this.

sudo apt install samba-client cifs-utils

Installing a user

This is very easy. If your username is “pi”, type

sudo smbpasswd -a pi

Just replace pi with whatever your user name is, set a password, and confirm it. You can add as many users as you like.

The SAMBA config file

SAMBA comes with an elaborate config file that allows you to specify your network sharing exactly as you want it, but it can be a bit overwhelming.

Open the SAMBA config file with

sudo nano /etc/samba/smb.conf

I have heard from a few users who had issues with this configuration file and given all the comments in the file, it is not always easy to know your way around.

This is why I have slimmed down this file to a minimum which you can just copy and paste in your config file.

To delete lines in the config file, hit CTRL+K. With this command, you will be able to quickly empty the editor window completely before pasting in this text:

[global]
client min protocol = SMB2
client max protocol = SMB3
vfs objects = catia fruit streams_xattr
fruit:metadata = stream
fruit:model = RackMac
fruit:posix_rename = yes
fruit:veto_appledouble = no
fruit:wipe_intentionally_left_blank_rfork = yes
fruit:delete_empty_adfiles = yes
security = user
encrypt passwords = yes
workgroup = WORKGROUP
server role = standalone server
obey pam restrictions = no
map to guest = never
[pi]
comment = Pi Directories
browseable = yes
path = /home/pi
read only = no
create mask = 0775
directory mask = 0775

This config file creates a Sharing Directory in /home/pi with rights only for the logged-in user and includes some optimization for macOS computers. You can probably make it even shorter if you are a real networking expert!

You can restrict access to your folders in many ways. “0700” only allows the user to modify the files. For further study on this subject, I recommend this article.

For all full overview of the various settings in this segment, I recommend a look at this page.

When you are done pasting, hit CTRL + O to write the file to disk and CTRL + X to exit the editor.

To test the syntax of your config file or see a summary of the settings, enter

testparm /etc/samba/smb.conf

You should see something along these lines:

rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[pi]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

Pressing “Enter” will just show you again what you have entered in the config file.

Finally, restart SAMBA:

sudo /etc/init.d/smbd restart

You should now see the name of your Raspberry Pi in your network. Connect to it using your username “pi” (in our example) and your password.

Whenever you reboot your Raspberry Pi, file sharing will automatically start.

Networking is sometimes a bit slow to recognize changes. If you are using macOS and you don’t see your Raspberry Pi after you made some changes, I recommend relaunching the Finder (Apple Menu > Force Quit).

Installing Samba on your Raspberry Pi and optimizing it for macOS computers 4

Conclusion

I hope this post was helpful for you to install SAMBA on your Raspberry Pi and to optimize it for the macOS machines on your network.

As always, I’d be happy to hear from you if you have any comments or suggestions.

Scroll to Top