How to set up Samba on Ubuntu 16.04 [Quick Guide]

How to set up Samba on Ubuntu 16.04 [Quick Guide]

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.

Requirements

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.

Installing Samba

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.

Samba NetBios nmbd is not needed for this guide so you can easily disable by this code:

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.

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:

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

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:

Output

After you press enter, this output will appear.

Output

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.

Creating Users

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:

Next step is to create directory under Samba server

You can add system user by this command

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.

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:

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”

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:

Now you are done with system configurations.

Leave a Reply

Your email address will not be published. Required fields are marked *