Setup Raspberry Pi Samba sharing how to install samba raspberry pi
The goal is to run Raspberry Pi as a file server, which can be accessed via Windows Explorer. The most suitable software solution for this is a Samba server. With Samba almost all functions of a
Windows server can be realized.
- File and directory shares (Shares)
- Printer releases
- Primary Domain Controller for NT (Samba 3)
- Active Directory Domain Controller (from Samba 4)
- Install Samba server.
- Samba server Basic configuration.
- Setup directory shares.
- Set Samba password for user.
Preliminary note to the following solutions
Compared to the usual tutorials and instructions for setting up Samba shares, this guide is a little more extensive. The reason is that a directory share is not the same as directory share. In general, you can share a directory with all users, for a specific group of users, or for a single user. In this guide, we consider all three possibilities. In each individual case, it is about who has which permissions must be set. This will save other instructions. But this is where the problems lie, if you want to set up individual releases yourself.
The following solution works with Raspbian Wheezy (Samba version 3) and Raspbian Jessie (Samba version 4).
Install Samba server Raspberry Pi
Relevant for the Samba server are the packages “samba” and “samba-common”. The package “smbclient” would not be necessary on a server. However, it has the advantage that you can test the shares locally on the server. This simplifies troubleshooting.
sudo apt-get update sudo apt-get install samba samba-common smbclient
Depending on the system, downloading and installing may take some time. It does not hurt to bring a little patience.
Then we check if Samba is running.
sudo service smbd status sudo service nmbd status
The output should be that the services “nmbd” and “smbd” are running.
Basic configuration Samba server
For the basic Samba configuration there is a central configuration file “/etc/samba/smb.conf”. This file is extremely extensive in the pre-configuration and therefore confusing. For a simple basic configuration, it is recommended to rename and rebuild the file.
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf_old sudo nano /etc/samba/smb.conf
The following basic configuration is not universal, but for most applications useful and appropriate. That is, for a start it is enough. Later, it may need to be customized.
[global] workgroup = WORKGROUP security = user encrypt passwords = yes
This basic configuration specifies a globally valid configuration. This is indicated by the area “global”, enclosed in square brackets. All information given therein applies to all later configured shares.
The parameter “workgroup” specifies the name of the workgroup. This has been structured in groups of computers in Windows networks computers. Today, this parameter is no longer relevant because newer versions of Windows no longer consider this specification. It is only included for compatibility reasons. This is typically called “workgroup” or “workgroup”.
The parameter “security” indicates which security level should apply when accessing the shares. The value “user” is a good choice and states that the user management of the server should be used. This means that access to the Samba shares is subject to the configured users and their authorizations on the server.
The parameter “encrypt passwords” with “yes” ensures that the passwords are encrypted during authentication. For safety reasons, a meaningful setting that brings no disadvantages in the use with it.
The last two lines are used to log in accesses without or with incorrect access data automatically as a guest. Only then will appropriate options apply if shares are to be released for everyone.
If you have entered this basic configuration in the file, you can save and close the file: Ctrl + O, Return, Ctrl + X.
Then we test this configuration file. This has the advantage that if we enter something wrong or incorrectly, then we can avoid the false start of the Samba server.
If there is no error here, then everything is ok. Otherwise, the error has to be fixed and the file has to be tested again.
After every change to the configuration file, the Samba services must be restarted. Only then will the configuration be adopted.
sudo service smbd restart sudo service nmbd restart
As long as the configuration is complete and correct, the Samba server will be up and running again.
Setup samba shares for directories
To set up directories, we first need a directory where we create the directories that we want to share later. In principle, it does not matter where the folder is located. Quite well is the home directory “/ home” in which we create a directory with the name “shares”. Here then the directories are created, which should be released.
sudo mkdir /home/shares
Then we create the directories that we want to release later and set the appropriate permissions.
Not all directories need to be created. You can also choose one for your own purposes and leave out the others.
General directory for everyone to test:
sudo mkdir /home/shares/test sudo chown root: root /home/shares/test/ sudo chmod 777 /home/shares/test/
Directory only for the user group “users”:
sudo mkdir /home/shares/users sudo chown root: users /home/shares/users/ sudo chmod 770 /home/shares/users/
Directory only for the user “pi”:
sudo mkdir /home/shares/pi sudo chown pi: pi /home/shares/pi/ sudo chmod 700 /home/shares/pi/
Then we open the Samba configuration file and enter the shares there.
sudo nano /etc/samba/smb.conf
Again, just enter the shares for which the directory was created.
[Samba Test] comment = Samba test release path = /home/shares/test read only = no
[Samba Users] comment = Samba Users Share path = /home/shares/users read only = no
[SambaPi] comment = Samba Pi release path = /home/shares/pi read only = no
The name of the share is enclosed in square brackets. This simplifies administration and access to the share.
The file must then be saved and closed: Ctrl + O, Return, Ctrl + X.
After changing the configuration file, a test is recommended.
If the test was successful then Samba needs to be restarted.
sudo service smbd restart sudo service nmbd restart
This makes sharing available on the network. However, the authorization to access it is still missing. What is meant is that for the user or users still Samba passwords must be set up.
Setup Samba password for users
For authentication, the user management is provided on the server. However, Samba uses only the configured usernames and file and directory permissions. Not the passwords. For each user who wants to use Samba shares, one must set up a separate password for Samba. Here we select the user “pi” as an example.
sudo smbpasswd -a pi
After entering the password you have to enter it a second time to check it. Then you can access the share.
Disable “pi” user for Samba:
sudo smbpasswd -d pi
Reactivate user “pi” for Samba:
sudo smbpasswd -e pi
Extension: Automatically mount Samba shares with “fstab”
In principle, a Samba share always consists of two pages. The server side and the client side. The Samba server was configured successfully in the best case. Now it’s about setting up or automatically mount the shared directory to the local file system of a client or other server.
Most problems are caused by incorrect or incomplete configuration of the Samba server, incorrect file and directory permissions, and incorrect username and password authentication.