Samba is a system used to create shares on a Linux system. These shares can be accessed on Linux, windows and mac. This is the perfect system to use if the server is planned to be used as a NAS. Within the guide I will go through the steps needed to install samba.

Install Samba

The installation itself of Samba isn’t the hardest part, most versions of Ubuntu have it available in their default repositories. The problem can be the configuring, but I will get to that in a minute. To install Samba use the following command:

sudo apt install samba

This will go through the process of installing Samba and starting it.

Setting up Users

For Samba to be able to accept a username and password it needs to know which users will be used to access it. To add an account to use Samba the following command can be used. In this example it will be adding the current user.

sudo smbpasswd -a $USER

This will then go on to ask for the password for that account. If the user changes their password at any time they will also need to update their samba password which can be done with a very similar command:

sudo smbpasswd $USER

Samba Group

This section is optional, however it does make it easier to manage who has access.

I tend to create a group that I can then set as the only valid users for the shares. Creating a group named smbgrp and then assigning the local user to that group can be done with the following commands:

sudo addgroup smbgrp
sudo usermod -aG smbgrg $USER

Configure Samba

Before making any changes to the Samba configuration files it is also best practice to to make a copy of it. This file can be used as a reference in the event of any config problems. To copy the file to a backup file use the following command:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.deafults

This will create a copy of the file with an extension of defaults in the same location as the original configuration file. The location of the backup file is personal preference.

Adding the Shares

To add a share we can add blocks in the configuration file. We can start editing it use whichever text editor feels comfortable, I will use nano in this example. To open the file use the following command:

sudo nano /etc/samba/smb.conf

Now the file is opened, navigate to the bottom of the file and add the following:

[sharename]
comment = This share is for share documents
path = /sharename
browsable = yes
writeable = yes
guest ok = no
valid users = smbgrp

The above will create a share for \\servername\share that is browseable by all, accessible by only users in the smbgrp group and writable. These blocks can be used to create any number of shares. For more information about the usable parameters in the configuration file you can find more on the Samba documentation site.

Restarting Samba Service

Once all the shares have been added to the configuration file, the service needs to be restarted this can be done with the following command:

sudo systemctl restart smbd

Optional Firewall Changes

If the server is running a ufw firewall the Samba ports can be opened using the following commands.

sudo ufw allow proto udp from 192.168.0.0/24 to any port 137
sudo ufw allow proto udp from 192.168.0.0/24 to any port 138
sudo ufw allow proto tcp from 192.168.0.0/24 to any port 139
sudo ufw allow proto tcp from 192.168.0.0/24 to any port 445

I have set the from IP range to 192.168.0.1-254 as this is a very common range, if it is not the correct range or any IP is needed it can be changed.


Justin Byrne

Justin Byrne is a self motivated tech enthusiasts. Spending more than half his life dedicated to the tech industry. He built his first computer at the age of 11, and has been building ever since. His interests have changed across the years from system building to web programming and even a dab of software engineering, and just like his interests, his operating system has changed sometimes more then 4 times a year.

0 Comments

Leave a Reply