In this article we will set up some samba file shares in Ubuntu 18.04, and secure them with username/password authentication, this is useful if you are setting up a NAS or Storage server that can later be accessed by most operating systems.

Samba is a free implementation of the SMB/CIFS networking protocol, this will provide file and print services that are compatible with normal Microsoft Windows clients and can integrate with a Microsoft Windows Server domain, either as a Domain Controller (DC) or as a domain member.

Step 1

Logging in to your server

ssh [email protected]

Make sure your OS is up to date.

sudo apt update && sudo apt upgrade -y

Once that is done we will install Samba and set up a username and password.

Note:

This is the simplest to set up but you can also set up Samba with Active Directory for authentication.

sudo apt install samba -y

Now we will set up a username and password

Note:

The user will need to be an existing one, below i will show the steps to add a new user, but you can skip this if you will be using an existing user.
optional:

sudo adduser --shell /bin/false 

set the samba password for the user

Note:

This should match the previous password:

sudo smbpasswd -a 

Step 2

Create a directory to be shared

sudo mkdir /mnt/

Set the correct owner and permissions for the newly created directory

sudo chown : /mnt/
sudo chmod 770 /mnt/

Configuring the shares in the Samba config file

Edit /etc/samba/smb.conf

sudo nano /etc/samba/smb.conf

Scroll to the bottom of the config file and add the following to create a share, and point it to the newly created directory.

....
[]
path = /mnt/
valid users = 
read only = no

Close and save with Control + X , Y and Enter
Restart the Samba service

sudo systemctl restart smbd

Now you are ready to set up the share in windows or any os by using the following details.

\\\

Username:

WORKGROUP\

Note:

The default group in the config file is called “WORKGROUP” but can be changed by editing the “/etc/samba/smb.conf”

That is all, now you have a functional file server with password protected windows shares.