Categories
Raspberry Pi

How to Install Samba on Raspberry Pi

Turn your Raspberry Pi into an NAS using Samba. Access the files on your Pi from any device on your network!

Install Samba on a Raspberry Pi | Overview

In this article we’re going to explain what the difference between Samba and a Samba Server is, why you should run a Samba Server, and finally how to install Samba on a Raspberry Pi.

What is Samba?

Samba is a piece of software that is installable on a wide variety of devices. Samba is a re-implementation of the SMB networking protocol. If you have both Unix and Windows clients on your network, Samba is great for sharing data between clients.

What is a Samba Server?

A Samba Server uses Samba to send and receive files. The difference between “Samba” and a “Samba Server” is that there is going to be one device (a Raspberry Pi) that is connected to a Hard Drive which allows you to store data on the Drive and then download it on other clients that want to connect to it. For example; let’s say that I’m on my Windows 10 PC and I want to open pictures or other files that I have stored on the Hard Drive. I can simply connect to my Raspberry Pi through SMB and then access the Hard Drive. I can either open files directly on the Hard Drive, or I can transfer them to my computer and open them that way.

Why Should You Run a Samba Server?

If you have a central server storing all of your data that is accessible on all of your devices, then you don’t have to go around and manually transfer files using a USB drive. You can simply connect to the server from your phone, laptop, desktop, etc. and download/upload the files as if you were connected directly to the Hard Drive. What this means for you and your Raspberry Pi is that we can make all the files on the Hard Drive connected to our Pi accessible to nearly every operating system. 

 

Let me give an example of what I do to better help this make sense to you. I use an app on my Google Pixel called Autosync. This app allows me to sync local folders on my phone and remote folders on the server. With this app I can set it on a routine so that every day/night at x time everything will sync with one another. Every night when my phone is charging Autosync will run and backup my photos folder, downloads folder, books folder, and audio books folder. This is great because I know that all of my pictures are getting stored in original quality and not being compressed. If I were to lose or break my phone, it wouldn’t be an immense problem.

How to Install Samba on Raspberry Pi and Configure it

It’s time to get into the tutorial! Below you’ll find easy to follow steps to convert your Raspberry Pi into a Samba Server.

What You'll Need to get Started

Everything you need

  • Raspberry Pi 4GB
  • On/Off Switch
  • Power Supply
  • Aluminum Heatsinks

Get it here!

1. Update and Upgrade the Pi

You’ll want to issue the following commands to update the programs and dependencies on your Pi that Samba depends on.

				
					sudo apt update
sudo apt full-upgrade
				
			

2. Download Samba

The following command will install the Samba package to your Raspberry Pi.

				
					sudo apt install samba samba-common-bin
				
			

3. Create a Folder or Mount Point You'd Like to Share

Now, you’ll want to create a folder that you’d like to share. I share my entire drive with Samba. If you’ll be doing this, skip the next command.

				
					mkdir /home/pi/shared
				
			

If you’ll only be sharing a folder, you can move on to step 4. If you’re like me and wish to share your entire Hard Drive, then you’ll want to create a mount point for it.

				
					sudo mkdir mnt/
cd mnt/
sudo mkdir usb/
				
			

Now we’ll want to grab the UUID of the drive and copy it.

				
					sudo blkid
				
			
				
					# Output of sudo blkid

/dev/sda1: LABEL="Seagate Expansion Drive" UUID="76BC33E8BC33A213" TYPE="ntfs" PARTUUID="2ce39f04-01"
				
			

Now, we’ll need to add an entry into the fstab configuration file to get the drive auto-mounted on system boot with the correct permissions. 

				
					sudo nano /etc/fstab
				
			
				
					# Add to bottom of file

UUID=76BC33E8BC33A213 /mnt/usb fstype defaults,auto,users,rw,nofail 0 0

				
			

4. Update the Samba Configuration with the Folder Information

Now, we’re going to update the Samba configuration file to let it know where our file is located, what permissions to use, and what to call the share.

				
					sudo nano /etc/samba/smb.conf
				
			

Add the following lines to the bottom of the file.

				
					[your_share_name]   # whatever you want your share to be called
workgroup = WORKGROUP   # name of work group, WORKGROUP is most common
path = /home/pi/shared  # path to shared folder or drive
writeable=yes   # allow the share to writeable
create mask=0777    # set drive to readable and writeable
directory mask=0777     # set drive to readable and writeable
public=no   # require login to access drive
				
			

To save and exit the file press Ctrl+X then press Y followed by Enter.

5. Create a User to Access the Share

As of now, our folder is being shared, however, we can’t connect to it. This is because we haven’t created a Samba user. We’ll do this in the next step.

				
					sudo smbpasswd -a pi
				
			

6. Restart the Samba Service for Changes to Take Effect.

The last step to get the Samba Service up and running is to restart it. 

				
					sudo systemctl restart smbd
				
			

7. Retrieve the Pi's IP Address

In order to connect to the Raspberry Pi we’ll need to grab its IP Address so we know where to point our other devices to. 

				
					hostname -I
				
			

8. Set Static IP Address of the Pi

Routers these days are typically pretty smart and won’t re-assign IP Addresses, however, it happens. To negate this potential issue, we’ll want to assign the Raspberry Pi a static IP address.

Now that we have the Raspberry Pi’s IP address, we’ll want to find the IP address of the router.

				
					ip r | grep default

				
			

Edit dhcpcd config file.

				
					sudo nano /etc/dhcpcd.conf
				
			

Add the following lines of code to the file.

				
					interface eth0 # wlan0 for wifi
static ip_address = 192.168.1.7/24 # whatever your Pi IP is, use it here
static routers = 192.168.1.1 # whatever your router IP is use it here
static domain_name_servers= 1.1.1.1 1.0.0.1 # these are Cloudflares DNS servers
				
			

The last step will be to reboot to make sure that everything is up and running.

				
					sudo reboot
				
			

Samba has been Successfully Setup, Time to Connect

We’ve successfully configured Samba. However, you’ll want to connect to it from another device to verify that everything works as intended. 

Connect to Samba on Windows

If you’re wanting to connect to your Samba Server from a Windows laptop or desktop, this is how you do it.

  1. Open “File Explorer.”
  2. Click “This PC” in the left navigation menu.
  3. Click “Map Network Drive.”
  4. Set a drive letter, example X:
  5. Next to “Folder” input “\\your_pis_ip\your_share_name.”
  6. Click “Finish”

That’s it, you should now be able to access the content inside of the folder that you shared.

Connect to Samba Server on Mac OS

If you’re a Mac OS user, you can use the following steps to connect to your Samba share.

  1. Open “Finder.”
  2. Click “Go” > “Connect to Server.”
  3. Enter the path to your Server “//your_pis_ip/your_share_name.”
  4. Click “Connect.”

That’s all you’ll need to connect to it. However, if you’d like to connect on boot, do the following.

  1. Click the Apple Logo.
  2. Click “System Preferences” > “Users and Groups.”
  3. Select your username.
  4. Select “Login Items.”
  5. Find the Pi shared network drive and click “Add.”

That’s it, it’s now connectable and will re-connect automatically on boot!

Connect to Samba Server on Android

If you have an Android Phone or tablet, you can use the following steps to access your Samba Server.

  1. Download “CX File Explorer” from the Play Store.
  2. Open the App.
  3. Tap “Network” > “New Location.”
  4. Tap “Remote” > “SMB.”
  5. Enter the Raspberry Pi IP Address, Samba username, and Samba Password.

That’s it, you should be connected to your Samba Server on your Android Phone!

Connect to Samba Server on iPhone

If you’re an iPhone user, you can use the following steps to connect to your drive.

  1. Open the “Files” app.
  2. Tap “Browse” at the bottom of the screen.
  3. Tap “…” at the top right of the screen.
  4. Tap “Connect to Server.”
  5. Enter “your_pi_address/your_share_name.”
  6. Press “Connect.”

And there you have it, you are connected to your Samba Server on an iPhone!

Get tutorials delivered to your inbox weekly.

More Posts

4 replies on “How to Install Samba on Raspberry Pi”

This is a Great tutorial! What HDD format type did you format your hard drive to make it work with your samba setup? NTFS/ExFAT/Ext4/HFS+/BTRFS/…
I would really like to make the HDD accessible to Windows, MacOS, Linux and Android as much as possible.

I’m glad that you found the tutorial helpful!

I would highly advise using a native Linux filesystem such as ext4 or XFS. I personally use ext4. I wouldn’t recommend using NTFS unless you plan to manually unplug the drive from your Pi and then plug it into your Windows PC. If the drive is formatted in Ext4, you will still be able to connect to it from your Windows PC through Samba.

In “3. Create a Folder or Mount Point You’d Like to Share” it says “cd mnt/” which doesn’t work here. Using “cd /mnt” instead worked.

Also your smb.conf snippet says “writeable=Yes” which results SMB server refusing to start and outputting errors. Changing it to “writeable=yes” fixed it.

No need to publish my comment unless you want to answer. 🙂

Leave a Reply

Your email address will not be published.