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.
Logging in to your server
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.
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
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.
sudo adduser --shell /bin/false <username>
set the samba password for the user
This should match the previous password:
sudo smbpasswd -a <username>
Create a directory to be shared
sudo mkdir /mnt/<folder_name>
Set the correct owner and permissions for the newly created directory
sudo chown <username>:<username> /mnt/<folder_name>
sudo chmod 770 /mnt/<folder_name>
Configuring the shares in the Samba config file
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.
.... [<share_name>] path = /mnt/<folder_name> valid users = <username> 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.
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.
Subscribe to UbuntuBoss: Easy Ubuntu Tutorials | How to for Ubuntu Linux
Get the latest posts delivered right to your inbox