Guide:Setting up an SMB (Windows) file server
Setting up an SMB(windows) file server in linux
This guide will show you how to share a directory using the SMB (windows file sharing)protocol to allow other clients to connect to it and share files amongst one another. I will also show how to make the share accessible by predefined users with passwords, or accessible to anybody.
There are many guides already detailing the exact same thing, why post a new one?
A lot of the guides I've seen have several problems which have stung me and resulted in many hours of hair pulling and frustration:
- Some use really old versions of the samba service and share definitions
- Others gloss over or skip file/directory permissions, resulting in "read only" shares and other such frustrations
- Quite a few poor practises (EG: using sudo $EDITOR $FILE, instead of sudoedit). Why that is good practise is detailed here.
ROCK64 board running Debian or Ubuntu
Access to terminal, either locally or via SSH
Some basic understanding of using the linux terminal: Howtogeek
Suggested: A basic comprehension of linux file permissions
Suggested: A USB storage device to host the shared directory on (to avoid filling up the System Partition)
This guide will start off from the directory created in a prior guide. You dont need to have the network share hosted on a USB drive, you can host it anywhere really, I just prefer hosting on this way to avoid filling up the boot partition.
Firstly, you'll need to update your repositories and install any pending updates. This is good practise before installing software on any linux system. Debian/Ubuntu use the "apt" package management tool. You'll need superuser access for this.
sudo apt update && sudo apt upgrade
Type in your password when prompted and y when prompted to install updates.
After that, you'll need to invoke apt to install the samba server:
sudo apt install samba samba-common-bin
Depending on your distro, samba-common-bin may already be installed. However, allow the other supporting software to be installed.
The next step is to create a directory to host the network share. In this senario, I will be placing it in the Flash drive mentioned in this tutorial.
Navigate to your mounted location. Following the linked tutorial, for me it is:
Make a new directory which will act as the shared location. We will create it with Use/Write/Execute permissions for everybody inside the folder:
sudo mkdir -m 1777 RockShare
Now we can edit Samba's configuration file to create a new share based on the directory we just set up:
Use the Up/Down or PageUp/Down keys to navigate to the bottom of the file to create a new entry.
[share] Comment = Rock64 Share Path = /media/USB-test3/RockShare Browseable = yes Writeable = Yes only guest = no create mask = 0777 directory mask = 0777 Public = yes Guest ok = yes
It should look somewhat similar to this after you've done editing it:
These options means that anybody can read, write or execute files in the share, either with a samba user or as a guest. To forbid guest access, simply omit the "guest ok" line. The title, in the square brackets, will be the name of the shared directory.
Now we can create a specialized user for samba, if you'd like to have your share accessible only with the proper credentials.
First of all, you need to make a new linux user. In this case, I will be making a new user "rocksmb":
sudo useradd rocksmb
After that, you can create a new samba user, and you'll be prompted to type in a password too. This is a unique password, independent to your linux user password:
sudo smbpasswd -a rocksmb New SMB password: Retype new SMB password: Added user rocksmb.
Now you restart the samba service:
sudo /etc/init.d/samba restart [ ok ] Restarting nmbd (via systemctl): nmbd.service. [ ok ] Restarting smbd (via systemctl): smbd.service. [ ok ] Restarting samba-ad-dc (via systemctl): samba-ad-dc.service.
Now your Samba share will be visible and accessible!
If you wish to add more users, you simply repeat the steps mentioned above: Create a linux user, then a samba user and password. You can also experiment with the above samba template, give predefined users different and unique folders if you wish, for example.
There are many guides about how to access smb shares using Windows:
In all cases, replace the hostname/[ http://wiki.pine64.org/index.php/Guide-Locating_your_device IP] in the guide with the ones you have.
If you want to access the drive using mobile apps, there are many apps available on both Android and iOS.
I dont have an iphone, so I'll do a quick rundown using the android app:
Download it and upen it to be greeted to a very simple credential screen. Simply fill in the details like:
In our case:
Assuming you've put in the right credentials, it will immediately open up the share using the default android file selector:
However Google's app is VERY rudimentary and barebones. I was able to open image files, but video and audio files gave me problems unless I copied them to internal memory.
If you need something more full featured, I highly recommend solid explorer:
Forum link: https://forum.pine64.org/showthread.php?tid=4983