Note: This post is part of a series. Each post builds on the previous ones. If you are just trying to add one thing to an existing system that was not built following this series, then I cannot promise that these instructions will work for you, although they probably will. If you’ve started from something other than a non-NOOBS Raspbian image, then you’ll probably need to adjust for that.

Please refer to the series Introduction for a list of all the different posts in the series.

Self-Promotion: I have recorded this series as a screencast for Pluralsight:
(http://www.pluralsight.com/courses/raspberry-pi-home-server)
If you have a Pluralsight subscription, please consider watching it. Reading the instructions is one thing, but watching it done demystifies the whole process.

Thank you!

Now that the Raspberry Pi has the space to hold your stuff, it’s about time it started doing something useful around the house. Its first task will be to share files from the hard drive. In the previous post we added a hard drive with two partitions, one ext4 partition for the operating system, and one NTFS partition to hold data. If you decided to format your data partition using the ext4 filesystem, then you’ll need to keep that in mind as we proceed.

Prerequisites

A Raspberry Pi

A mounted, USB hard drive with space for the stuff you want to share
Mine is the second hard drive partition, mounted at /mnt/data

Install Samba

The “Samba” package creates network file shares in a way that Mac, Windows, and other Linux computers on the network will understand. Install Samba as follows:

sudo apt-get install samba samba-common-bin

That’s all there is to the installation, but there’s a bit of configuration before there will be anything to see over the network.

Set up shares

In the previous version of this article, I used Webmin to do the heavy lifting of setting up the shares. In all the time I’ve been running my Raspberry Pi Home Server, I’ve found that this is the only thing I ever really used Webmin for, though. As a result, this version of the series will set up the shares manually, and the Webmin article has been moved to the end as an optional step.

To create a share, you first create a folder that you want to share, tell Samba to share it, and set up the permissions correctly so that users connecting to the share through Samba will be able to write to it.

You can get into all kinds of detail about who can and can’t write what and where, but I’ll leave that up to you to explore on your own. What I’ll be setting up is a simple public share to be used by the family members in my house. The permissions will be wide open on this share.

Create the folder to be shared

First, create a folder to be shared. I’ll call mine “public”, and put it in the root of the hard drive I mounted in a previous post.

mkdir /mnt/data/public

Take a look at the permissions for the newly-created folder

ls -l /mnt/data

You’ll see that the new folder belongs to the “root” user and group even though we created it without using “sudo”. This is because my filesystem is NTFS, and it doesn’t support Linux’s file system permission system. If you made your data partition ext4, then this is going to cause problems for the Samba user. Assign the folder’s ownership to the “nobody” user and the “nogroup” group.

sudo chown nobody:nogroup /mnt/data/public

Check out the result

ls -l /mnt/data

If your filesystem is NTFS, this will have had no effect. If your filesystem is ext4 though, you should see that the public folder is now owned by “nobody” and “nogroup”. Now let’s share this folder with the network.

Open the Samba configuration file using nano

sudo nano /etc/samba/smb.conf

This file is pretty well documented, and will explain most things that you need inline. We’ll be making a number of changes.

Enable WINS support

Windows Internet Name Service (WINS) is kind of like the Domain Name System (DNS) that turns web addresses into IP addresses when you use a browser. WINS does this inside of your own network so that instead of having to remember your server’s IP address, you can refer to it by name.

Scroll down in the file a little until you see the “Global Settings” section. If your home network is using a different workgroup name than “WORKGROUP”, you’ll want to change that here. If you don’t know what that means, then you probably haven’t changed your workgroup name, so you can just leave it alone.

Just below that is a commented-out line that says “wins support = no”. Uncomment this by removing the pound sign from the beginning of the line, and change “no” to “yes”.

Scroll down a little, and just before the Networking section, add a line that says

guest account = nobody

Scroll down to the bottom of the file, and add a new section that defines the new public share.

[public]
path = /mnt/data/public
public = yes
writeable = yes

Close and save the file (Ctrl-X,Y), and then restart the Samba service

sudo service smbd restart

That should do it. You should now be able to see the public share from the other computers on your network. You should also be able to refer to your server by name now instead of by address, and that includes when connecting via RealVNC.

Give it a try now. Open a file manager, and navigate to “\\rphs\public”. You should be able to create and edit files in this share without any restrictions.

Disclaimer

This is a wide-open file share. Anyone on the local network can add, edit, or delete the files it contains. I’m more interested in having a place to put stuff than in controlling access to it. Controlling access to the drive contents is beyond the scope of this post, but may be a subject for a future post.

Make some folders

Create some file folders in the Public share to hold your stuff, and copy it in. Music, Pictures, Videos, anything you want. For this server, I’ve created the following folder structure.

Documents

Downloads

Music

Pictures

Videos

You don’t have to use the same structure as me, of course, but this is the one I’ll be using in future posts, so if you structure your differently, just remember to adjust any paths in future posts accordingly.

Load it up

When it comes to copying the files in, you can save some time, and skip the network bottleneck by moving the external hard drive to the computer that currently has the data. Because the data partition was formatted as NTFS in the previous post, when you plug it in to your Windows or Mac computer, you’ll just see a drive called “Data”, or whatever you named it.

Remember to shut down the Raspberry Pi before removing the hard drive, of course. Just put it back when you’re done copying files, and start up the Raspberry Pi as usual.

Wrapping up

You now have a public share that exposes the data partition on the hard drive attached to the Raspberry Pi Home Server. You can use this to store your media and documents on the network so that they are accessible to your other computers and devices.

You’ve finished another article, so it’s time to shut down the Pi, and take a backup of the SD card.

What’s next?

In the next post, we’ll get a media server up and running so that you can stream music and movies all over your house from the hard drive share.

16 Responses to Raspberry Pi Home Server v2: Sharing Files with Samba

Hi Mel,
I seem to be having some issues here which is surprising with how simple the directions are. I’ve done the apt-get which seems to have gong smoothly. It created the /etc/samba/ directory & I’m able to edit the smb.conf but after all that I can’t restart samba. Using the command “sudo service smbd restart” I get the error “failed to load: no such file or directory.” I’ve tried to restart the pi & run the apt-get a second time but when I check /etc/init.d/ I don’t see the smbd directory. What am I missing?

this is a very nice series especialy if your a PI noob like me. I have been succesfull all the way up to here .I did restart the service and all but on the pi when I browse to \\rphs\public…it just goes to “/” am I missing something ?

Start by just navigating to \\rphs and see if there are any shares at all. Maybe the name came out wrong. If you’re saying that the share is there, but it’s showing you the wrong thing, then check the samba config for that share and make sure it’s pointing to the right place (e.g. /mnt/data/public)

Thx…I decided to follow your webmin instalation and the share is there. I assumed I will be able to browse to the share from the pi. but turns out I can only see the share from my windows drive. No matter it is working. thats the important part. Super thx for the quick response.

Hi Mel,
I was able to setup samba successfully & can move files from my computer to pi but it seems the permissions on my /public folder is stopping me from moving the file around on my pi’s desktop. I keep getting “Error moving file: Permission denied.” The only workaround I’ve found is doing a sudo cp or sudo mv. How can I fix this?

You’ll need to examine two things here. Who are you logged into the desktop as (I usually use the Pi user), and who owns the folder and/or files you’re trying to manipulate. If you use an NTFS filesystem on the public share, then Linux doesn’t really understand the security system, so everything stays public, pretty much. That’s one of the reasons I use ntfs on my external drive. It also makes the drive more portable. If you’ve used ext4, then you need to start worrying more about who owns the share, and the files within it, and things get a little more complicated. Another thing to consider is where the files came from. If they were copied in over the nestwork through the share, then they should all be public to begin with. If they were copied/moved in from elsewhwere on the Pi’s filesystem, then they would retain their original permissions (on an ext4 filesystem, that is). You can change the ownership or permissions using chown and chmod if they aren’t what you’re expecting.

Hi Mel,
I’m really thankfull for your guide, I’m a Linux and Raspberry Pi newbie and was having quite a trouble trying to set up samba between two Pis at home and finally it worked! I was able to see the shared folder from one Pi on the other. But I had a problem after I shutted them off. When I turned them on again, I couldn’t see the shared folder on the client Pi anymore. All that is shown is an error message “Message did not receive a reply. The location is not mounted.”. Do you know what might have happened?

From the message, it sounds like maybe you were trying to mount the network share on the client. Maybe the share wasn’t ready yet when the client started up. I’ve never tried that myself. If that’s not what you were doing, then I’m probably off base. Make sure the server is fully up and running, and then try starting the client and see if it makes a difference.

Hello. Your guide has been really insightful, I was wondering about security of the server. I know you wrote controlling access is outside the scope of this article, but I was wondering if you had any recommendations on where to look? Also does your guide include ways to access the server from outside the local network?

I use my server as an inside-the-house thing. I don’t expose anything to the outside other than the VPN and the remote access that the built-in VNC server provides. If I need to see something on the home network when I’m away, I either remote to the Pi’s desktop, or I connect the VPN and look around the network directly. If you were wanting to expose something like, say, a WordPress instance to the outside in order to run a blog from your house, then the security concerns have more to do with WordPress than with the Pi specifically. Similarly, if you wanted to run OwnCloud on the Pi, then you need to keep up to date on any OwnCloud updates or security alerts. Basically, as soon as you open a port to the outside world, you need to do the research on what’s listening. It’s not something I can give blanket advice on.

The VNC server that’s built into current raspbian images can be used remotely once you sign up for a free account. SSH would require you to set up a VPN solution like OpenVPN and connect through that. The built in VNC is by far the easiest solution though.