What is Samba?
Samba is a software application of SMB networking protocol used for printer connection, Directory service for domain networks and to build multiple platform file shares.
In this tutorial you will learn how to install and set-up Samba server to provide different networked file stores and shares for multiple organizations. You will also be able to get access the shares from Windows and Linux.
You need an Ubuntu 16.04 server, you can get all information from its set-up guide. Keep in mind, you need a large server size as it requires more space.
Get 50$ Credit on Vulture Clouds Here and Test the Instruction for free.
You can easily install Samba using Ubuntu package.
First set will be upgrading the packages before installing new one. You can use these commands to update and install.
$sudo apt-get update (To update) $sudo apt-get install samba (To install and begin the Samba server)
Samba NetBios nmbd is not needed for this guide so you can easily disable by this code:
$sudo systemctl stop nmbd.service $sudo systemctl disable nmbd.service
This will disable the nmbd, if you are still facing security problems than you can disable the Samba Server until it is installed and ready to use.
$sudo systemctl stop smbd.service
Samba server is now finally installed and ready to use.
Setting up Samba’s Global Options
There is a configuration file which you can find at /etc/samba/smb.conf.
This file has 2 sections, Global and Shares.
Global Section shows the nature of Samba Server, whereas the Shares section shows how many files are shared. Instead of editing the file, you can create a new one by this command:
$sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.orig
The global part of this file will help you to know the server name, role, interfaces and other details regarding networking.
Got to /etc/samba/smb.conf
[Global] Server string = samba_server Server role = standalone server Interfaces = lo your_network_interface Bind interfaces only = yes Disable netbios = yes smb ports = 445 Log file = /var/log/samba/smb.log Max log size = 10000
These commands define the following:
Server String: – Details which is given during the time of connection is called server string. Samba server or any other name can be used to recognize the server. This guide will show you strings to express the samba shares.
Server Role: – It will tell you which kind of Samba Server is created. In this scenario Standalone server is used. Other type of servers are domain members and controllers.
Interfaces: – Samba server is restricted to network interfaces only. “Lo” is used here which is a loopback interface. Apart from this, external interface should also be added. Mostly Eth0 is used as external interface.
Bind Interface Only: – This guarantees that Samba Server is only restricted to the interfaced which is given in interface line, and avoid other bundles which is not included in a particular interface.
Disable netbios: – It disable all netbios functions in a server to make the server name resolution process a little bit easy and to free SMB traffic
SMB ports: – It is used to set the port which server will function on. Samba uses 445 port as default.
Log File: – This assign the location and name of Samba File.
Max Log Size: – By using this you can set a size which you can’t exceed. I prefer you to set a large size as per your system resources. If by chance you reach the size you’ve set up, it will delete the current file and will create a duplicate file and will move the previous elements of the file to the new one. It will use old extension.
This command will help you to keep free space in your disk and will prevent it from getting full.
If you need a comprehensive logging, then you can use this command
Log level = 3 passdb:5 auth:5
Log-in level 3 means that details are higher as compared to standard log-in. Standard log-in level is 1 where you will get minimum log-in details. Highest level is 5 where you will get maximum details and all knowledge regarding to a user.
After creating logging section, you should save and close it.
If you ever want to edit Smb.conf file, you should check for Syntax errors by running Samba utility testparm.
When you will run the test parm command, this output will appear:
Load smb config files from /etc/samba/smb.conf Loaded services file OK. Server role: ROLE_STANDALONE
After you press enter, this output will appear.
# Global parameters [global] server string = samba_server interfaces = lo your_network_interface bind interfaces only = Yes server role = standalone server log file = /var/log/samba/smb.log max log size = 10000 smb ports = 445 disable netbios = Yes idmap config * : backend = tdb
If this testparm shows the command “Load services files OK” that means this file is free of errors, and nothing can stop Samba Server to start.
Now you know how to start Samba Server, but this is not the only thing you have to learn. For more functionalities, you should know how to share config. A share consist of 2 parts, a user and a directory, which is used for logins and testing purpose.
In this section, you will learn how to create user profiles which can access the server. They should have access on servers as the user when they log in, so that they can they can use read and write features in the system.
Apart from normal users, you also have to create an admin user which should have access on personal shares, as well as ordinary shares.
Home Directories should be created for each single user. Instead of using standard directory for every user, it’s better to have a personal directory to keep the data separated, and to backup data easily when required.
First you have to create Directory where samba data will be stored, after it’s installed a group will be created called samba share
To create the group follow this code:
sudo mkdir /samba/ sudo chown sambashare /samba/
Next step is to create directory under Samba server
sudo mkdir /samba/name
You can add system user by this command
sudo adduser --home /samba/name --no-create-home --shell /usr/sbin/nologin --ingroup sambashare name
These options are defined as follows:
Home: This command adds the location of particular user’s home directory
No Create Home: This command restricts a user to create any home directory. It will help to avoid configuration files that are not in use.
Shell: This command is used to check which shell user will be given to user when he logs in by SSH
In Group Samba Share: This includes the user in Samba Share group, by which they will have full access on their shares, also they will have features to read and write in group.
Now you are ready to give full control and authorization on user home directory.
sudo chown david:sambashare /samba/name/ sudo chmod 2770 /samba/name/
Setting all authorizations means that, any new file which is created on this “Name” directory will have whole group ownership of parent class. If a particular admin create any file, then this group owner can access that, also he can edit it.
Next step is to create a unique password for log in purpose. You can easily do by using smbpasswd command:
sudo smbpasswd -a name sudo smbpasswd -e name
With this password you can have log in to Samba share without SSH in the server.
After following this steps, finally you’ll be a part of system user, and are registered as Samba user.
These options are defined as follows:
a: – It is used to add a user to Samba Share. It does not enable it.
e: – It is used to enable previous user.
If you want to create Admin user than you can use this following code, but don’t forget to change the home directory to “everyone”
sudo mkdir /samba/everyone sudo adduser --home /samba/everyone --no-create-home --shell /usr/sbin/nologin --ingroup sambashare admin sudo chown admin:sambashare /samba/everyone/ sudo chmod 2770 /samba/everyone/ sudo smbpasswd -a admin sudo smbpasswd -e admin
If there is more than one admin user, than it’s better to create a group. Instead of repeating this long process again and again to add new admins, it is efficient to create a group. Admins which are no longer required, or admins which are to be added, all can be done by one single command.
New group can be created, and user admin can be easily added by this command:
$sudo groupadd admins $sudo usermod -G admins admin
Now you are done with system configurations.